mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio: Add TestPauseBeforeInit
This confirms that Pause before initialization should not launch another loop.
This commit is contained in:
parent
7e2a679b17
commit
bd85d0e08d
@ -258,7 +258,7 @@ type playerImpl struct {
|
||||
sampleRate int
|
||||
playing bool
|
||||
closedExplicitly bool
|
||||
runningReadLoop bool
|
||||
isLoopActive bool
|
||||
|
||||
buf []byte
|
||||
pos int64
|
||||
@ -375,12 +375,12 @@ func (p *playerImpl) Play() {
|
||||
}
|
||||
|
||||
p.playing = true
|
||||
if p.runningReadLoop {
|
||||
if p.isLoopActive {
|
||||
return
|
||||
}
|
||||
|
||||
// Set p.runningReadLoop to true here, not in the loop. This prevents duplicated active loops.
|
||||
p.runningReadLoop = true
|
||||
// Set p.isLoopActive to true here, not in the loop. This prevents duplicated active loops.
|
||||
p.isLoopActive = true
|
||||
p.context.addPlayer(p)
|
||||
|
||||
go p.loop()
|
||||
@ -401,7 +401,7 @@ func (p *playerImpl) loop() {
|
||||
p.m.Lock()
|
||||
p.playing = false
|
||||
p.context.removePlayer(p)
|
||||
p.runningReadLoop = false
|
||||
p.isLoopActive = false
|
||||
p.m.Unlock()
|
||||
}()
|
||||
|
||||
|
@ -106,3 +106,22 @@ func TestSameSourcePlayers(t *testing.T) {
|
||||
t.Errorf("got: nil, want: an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPauseBeforeInit(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
src := BytesReadSeekCloser(make([]byte, 4))
|
||||
p, err := NewPlayer(context, src)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p.Play()
|
||||
p.Pause()
|
||||
p.Play()
|
||||
|
||||
if err := UpdateForTesting(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user