mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-05 07:24:30 +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
|
sampleRate int
|
||||||
playing bool
|
playing bool
|
||||||
closedExplicitly bool
|
closedExplicitly bool
|
||||||
runningReadLoop bool
|
isLoopActive bool
|
||||||
|
|
||||||
buf []byte
|
buf []byte
|
||||||
pos int64
|
pos int64
|
||||||
@ -375,12 +375,12 @@ func (p *playerImpl) Play() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.playing = true
|
p.playing = true
|
||||||
if p.runningReadLoop {
|
if p.isLoopActive {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set p.runningReadLoop to true here, not in the loop. This prevents duplicated active loops.
|
// Set p.isLoopActive to true here, not in the loop. This prevents duplicated active loops.
|
||||||
p.runningReadLoop = true
|
p.isLoopActive = true
|
||||||
p.context.addPlayer(p)
|
p.context.addPlayer(p)
|
||||||
|
|
||||||
go p.loop()
|
go p.loop()
|
||||||
@ -401,7 +401,7 @@ func (p *playerImpl) loop() {
|
|||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
p.playing = false
|
p.playing = false
|
||||||
p.context.removePlayer(p)
|
p.context.removePlayer(p)
|
||||||
p.runningReadLoop = false
|
p.isLoopActive = false
|
||||||
p.m.Unlock()
|
p.m.Unlock()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -106,3 +106,22 @@ func TestSameSourcePlayers(t *testing.T) {
|
|||||||
t.Errorf("got: nil, want: an error")
|
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