mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-04 23:14:28 +01:00
audio: Bug fix: (*Context).IsReady never returned true unless there is a player
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. Play a dummy player to avoid the blocking. Fixes #969
This commit is contained in:
parent
f34e94ff2c
commit
b78f678700
@ -185,8 +185,25 @@ func (c *Context) removePlayer(p *playerImpl) {
|
|||||||
// On some browsers, user interaction like click or pressing keys is required to start audio.
|
// On some browsers, user interaction like click or pressing keys is required to start audio.
|
||||||
func (c *Context) IsReady() bool {
|
func (c *Context) IsReady() bool {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
|
defer c.m.Unlock()
|
||||||
|
|
||||||
r := c.ready
|
r := c.ready
|
||||||
c.m.Unlock()
|
if r {
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
if len(c.players) != 0 {
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create another goroutine since (*Player).Play can lock the context's mutex.
|
||||||
|
go func() {
|
||||||
|
// 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.
|
||||||
|
// Play a dummy player to avoid the blocking (#969).
|
||||||
|
p, _ := NewPlayerFromBytes(c, make([]byte, bytesPerSample))
|
||||||
|
p.Play()
|
||||||
|
}()
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user