audio: Add TestPauseBeforeInit

This confirms that Pause before initialization should not launch
another loop.
This commit is contained in:
Hajime Hoshi 2019-05-02 21:36:55 +09:00
parent 7e2a679b17
commit bd85d0e08d
2 changed files with 24 additions and 5 deletions

View File

@ -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()
}()

View File

@ -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)
}
}