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