mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio: Bug fix: Do not create players every call of IsReady
Close #1709
This commit is contained in:
parent
6d0ffeb7d8
commit
4b7064ac58
@ -71,6 +71,7 @@ type Context struct {
|
|||||||
sampleRate int
|
sampleRate int
|
||||||
err error
|
err error
|
||||||
ready bool
|
ready bool
|
||||||
|
readyOnce sync.Once
|
||||||
|
|
||||||
players map[playerImpl]struct{}
|
players map[playerImpl]struct{}
|
||||||
|
|
||||||
@ -255,7 +256,9 @@ func (c *Context) IsReady() bool {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.readyOnce.Do(func() {
|
||||||
// Create another goroutine since (*Player).Play can lock the context's mutex.
|
// Create another goroutine since (*Player).Play can lock the context's mutex.
|
||||||
|
// TODO: Is this needed for reader players?
|
||||||
go func() {
|
go func() {
|
||||||
// The audio context is never ready unless there is a player. This is
|
// The audio context is never ready unless there is a player. This is
|
||||||
// problematic when a user tries to play audio after the context is ready.
|
// problematic when a user tries to play audio after the context is ready.
|
||||||
@ -264,6 +267,7 @@ func (c *Context) IsReady() bool {
|
|||||||
p := NewPlayerFromBytes(c, make([]byte, bufferSize()*2))
|
p := NewPlayerFromBytes(c, make([]byte, bufferSize()*2))
|
||||||
p.Play()
|
p.Play()
|
||||||
}()
|
}()
|
||||||
|
})
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user