Skip to content

Commit

Permalink
audio: bug fix: (*Player).Position is not updated correctly
Browse files Browse the repository at this point in the history
Update might not be called or delayed when the window is in background
and invisible on macOS. Let's use a distinct groutine to update the
audio player states.

Closes #3154
  • Loading branch information
hajimehoshi committed Nov 6, 2024
1 parent 20014ad commit 7b5054c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions audio/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,22 @@ func NewContext(sampleRate int) *Context {
c.setReady()
}()
}

if err := c.updatePlayers(); err != nil {
return err
}
return nil
})

// In the current Ebitengine implementation, update might not be called when the window is in background (#3154).
// In this case, an audio player position is not updated correctly with AppendHookOnBeforeUpdate.
// Use a distinct goroutine to update the player states.
go func() {
for {
if err := c.updatePlayers(); err != nil {
c.setError(err)
return
}
time.Sleep(time.Second / 100)
}
}()

return c
}

Expand Down

0 comments on commit 7b5054c

Please sign in to comment.