Reduce direct dependency on Player even more

This commit is contained in:
Michael Manganiello
2023-06-18 22:45:05 -03:00
parent 4629ede7a7
commit 7161dd40a9
3 changed files with 36 additions and 23 deletions
+17 -1
View File
@@ -40,6 +40,7 @@ type PlaybackManager struct {
onSongChange []func(nowPlaying, justScrobbledIfAny *mediaprovider.Track)
onPlayTimeUpdate []func(float64, float64)
onLoopModeChange []func(string)
}
func NewPlaybackManager(
@@ -128,6 +129,11 @@ func (p *PlaybackManager) OnPlayTimeUpdate(cb func(float64, float64)) {
p.onPlayTimeUpdate = append(p.onPlayTimeUpdate, cb)
}
// Registers a callback that is notified whenever the loop mode changes.
func (p *PlaybackManager) OnLoopModeChange(cb func(string)) {
p.onLoopModeChange = append(p.onLoopModeChange, cb)
}
// Loads the specified album into the play queue.
func (p *PlaybackManager) LoadAlbum(albumID string, appendToQueue bool, shuffle bool) error {
album, err := p.sm.Server.GetAlbum(albumID)
@@ -294,7 +300,17 @@ func (p *PlaybackManager) SetReplayGainOptions(config ReplayGainConfig) {
// Changes the loop mode of the player to the next one.
// Useful for toggling UI elements, to change modes without knowing the current player mode.
func (p *PlaybackManager) SetNextLoopMode() error {
return p.player.SetNextLoopMode()
if err := p.player.SetNextLoopMode(); err != nil {
return err
}
defer func() {
for _, cb := range p.onLoopModeChange {
cb(p.player.GetLoopMode().String())
}
}()
return nil
}
// call BEFORE updating p.nowPlayingIdx