Add Loop functionality to player controls

Adding the Loop functionality, along with the Player changes to support
it, and a button to the player controls.

`Player` now has a `loopMode` attribute, which determines whether it
should loop. At the moment, only the following modes are supported:

* `LoopNone`: Disables loop.
* `LoopAll`: Enables loop for the entire playlist queue.

This has been designed as an enum, to support other modes in the future
(e.g. loop for the current track only).

It depends on the `loop` functionality provided by MPV (using the
[`loop-playlist` option](https://mpv.io/manual/master/#options-loop-playlist)),
so no custom logic is needed to reset the currently playing index.
This commit is contained in:
Michael Manganiello
2023-06-18 22:43:03 -03:00
parent 1f272829c7
commit 2ab19f65e1
4 changed files with 102 additions and 10 deletions
+6
View File
@@ -46,6 +46,9 @@ func NewBottomPanel(p *player.Player, contr *controller.Controller) *BottomPanel
p.OnStopped(func() {
bp.Controls.SetPlaying(false)
})
p.OnLoopModeChanged(func(mode string) {
bp.Controls.SetLoopMode(mode)
})
bp.NowPlaying = widgets.NewNowPlayingCard()
bp.NowPlaying.OnShowCoverImage = func() {
@@ -87,6 +90,9 @@ func NewBottomPanel(p *player.Player, contr *controller.Controller) *BottomPanel
bp.Controls.OnSeek(func(f float64) {
p.Seek(fmt.Sprintf("%d", int(f*100)), player.SeekAbsolutePercent)
})
bp.Controls.OnChangeLoopMode(func() {
p.SetNextLoopMode()
})
bp.AuxControls = widgets.NewAuxControls(p.GetVolume())
bp.AuxControls.VolumeControl.OnVolumeChanged = func(v int) {