Skip to content

Commit 19d1d40

Browse files
committed
audio state set during gui setup if necessary
completes work started in 4bb7862
1 parent 4bb7862 commit 19d1d40

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

gui/ebiten/audio.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ func (a *audioPlayer) setState(state gui.State) {
2222
a.crit.Lock()
2323
defer a.crit.Unlock()
2424
a.state = state
25-
if state == gui.StatePaused {
26-
a.p.Pause()
27-
} else {
28-
a.p.Play()
25+
if a.p != nil {
26+
if state == gui.StatePaused {
27+
a.p.Pause()
28+
} else {
29+
a.p.Play()
30+
}
2931
}
3032
}
3133

gui/ebiten/gui.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ func Launch(endGui <-chan bool, g *gui.ChannelsGUI, update func() error) error {
321321
for !done {
322322
select {
323323
case eg.state = <-g.State:
324+
// audio player is not ready yet so we don't really need to push the state change as we
325+
// do in the main update loop. however, we do so anyway in case something changes above
326+
// and we forget about this. there's no harm or performance penalty in setting the state
327+
// like this
328+
eg.audio.setState(eg.state)
324329
done = true
325330
case <-endGui:
326331
return nil

0 commit comments

Comments
 (0)