Add functionality to repeat current track

This new Loop mode keeps reproducing the current track, unless it is
changed using the player controls to go to the next/previous track.

As in other applications, this is set by using the "Repeat" button,
which now goes from "Off" -> "Repeat All" -> "Repeat One".
This commit is contained in:
Michael Manganiello
2023-06-20 23:23:38 -03:00
parent 5f83c2cd95
commit 196f7f2cff
2 changed files with 24 additions and 1 deletions
+19 -1
View File
@@ -58,12 +58,13 @@ type ReplayGainOptions struct {
// Fallback gain intentionally omitted
}
// The playback loop mode (LoopNone, LoopAll).
// The playback loop mode (LoopNone, LoopAll, LoopOne).
type LoopMode int
const (
LoopNone LoopMode = iota
LoopAll
LoopOne
)
// Information about a specific audio device.
@@ -420,10 +421,23 @@ func (p *Player) SetLoopMode(mode LoopMode) error {
if err := p.mpv.SetOptionString("loop-playlist", "no"); err != nil {
return err
}
if err := p.mpv.SetOptionString("loop-file", "no"); err != nil {
return err
}
case LoopAll:
if err := p.mpv.SetOptionString("loop-playlist", "inf"); err != nil {
return err
}
if err := p.mpv.SetOptionString("loop-file", "no"); err != nil {
return err
}
case LoopOne:
if err := p.mpv.SetOptionString("loop-playlist", "no"); err != nil {
return err
}
if err := p.mpv.SetOptionString("loop-file", "inf"); err != nil {
return err
}
}
p.loopMode = mode
@@ -437,6 +451,8 @@ func (p *Player) SetNextLoopMode() error {
case LoopNone:
return p.SetLoopMode(LoopAll)
case LoopAll:
return p.SetLoopMode(LoopOne)
case LoopOne:
return p.SetLoopMode(LoopNone)
default:
return nil
@@ -650,6 +666,8 @@ func (l LoopMode) String() string {
return "no"
case LoopAll:
return "all"
case LoopOne:
return "one"
}
return "UNKNOWN_LOOP_MODE"
}
+5
View File
@@ -68,8 +68,13 @@ func (a *AuxControls) OnChangeLoopMode(f func()) {
func (a *AuxControls) SetLoopMode(mode string) {
if mode == "all" {
a.loop.Importance = widget.HighImportance
a.loop.Icon = theme.MediaReplayIcon()
} else if mode == "one" {
a.loop.Importance = widget.HighImportance
a.loop.Icon = theme.MediaReplayIcon() // TODO: This icon must be changed to the "Repeat" one with a 1.
} else {
a.loop.Importance = widget.MediumImportance
a.loop.Icon = theme.MediaReplayIcon()
}
a.loop.Refresh()
}