mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
examples/audio: Add 'Now Loading' phase
This commit is contained in:
parent
252fee56d3
commit
86aeda2c9d
@ -28,10 +28,25 @@ const (
|
||||
screenHeight = 240
|
||||
)
|
||||
|
||||
var audioContext *audio.Context
|
||||
var (
|
||||
audioContext *audio.Context
|
||||
audioLoadingDone chan struct{}
|
||||
audioLoaded bool
|
||||
)
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()))
|
||||
if !audioLoaded {
|
||||
select {
|
||||
case <-audioLoadingDone:
|
||||
audioLoaded = true
|
||||
default:
|
||||
}
|
||||
}
|
||||
msg := fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS())
|
||||
if !audioLoaded {
|
||||
msg += "\nNow Loading..."
|
||||
}
|
||||
ebitenutil.DebugPrint(screen, msg)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -43,15 +58,22 @@ func main() {
|
||||
}
|
||||
// TODO: sampleRate should be obtained from the ogg file.
|
||||
audioContext = audio.NewContext(22050)
|
||||
audioLoadingDone = make(chan struct{})
|
||||
// TODO: This doesn't work synchronously on browsers because of decoding. Fix this.
|
||||
go func() {
|
||||
s, err := audioContext.NewVorbisStream(f)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
}
|
||||
p, err := audioContext.NewPlayer(s)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
}
|
||||
close(audioLoadingDone)
|
||||
p.Play()
|
||||
}()
|
||||
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "PCM (Ebiten Demo)"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user