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:
+19
-1
@@ -58,12 +58,13 @@ type ReplayGainOptions struct {
|
|||||||
// Fallback gain intentionally omitted
|
// Fallback gain intentionally omitted
|
||||||
}
|
}
|
||||||
|
|
||||||
// The playback loop mode (LoopNone, LoopAll).
|
// The playback loop mode (LoopNone, LoopAll, LoopOne).
|
||||||
type LoopMode int
|
type LoopMode int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LoopNone LoopMode = iota
|
LoopNone LoopMode = iota
|
||||||
LoopAll
|
LoopAll
|
||||||
|
LoopOne
|
||||||
)
|
)
|
||||||
|
|
||||||
// Information about a specific audio device.
|
// 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 {
|
if err := p.mpv.SetOptionString("loop-playlist", "no"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := p.mpv.SetOptionString("loop-file", "no"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
case LoopAll:
|
case LoopAll:
|
||||||
if err := p.mpv.SetOptionString("loop-playlist", "inf"); err != nil {
|
if err := p.mpv.SetOptionString("loop-playlist", "inf"); err != nil {
|
||||||
return err
|
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
|
p.loopMode = mode
|
||||||
|
|
||||||
@@ -437,6 +451,8 @@ func (p *Player) SetNextLoopMode() error {
|
|||||||
case LoopNone:
|
case LoopNone:
|
||||||
return p.SetLoopMode(LoopAll)
|
return p.SetLoopMode(LoopAll)
|
||||||
case LoopAll:
|
case LoopAll:
|
||||||
|
return p.SetLoopMode(LoopOne)
|
||||||
|
case LoopOne:
|
||||||
return p.SetLoopMode(LoopNone)
|
return p.SetLoopMode(LoopNone)
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
@@ -650,6 +666,8 @@ func (l LoopMode) String() string {
|
|||||||
return "no"
|
return "no"
|
||||||
case LoopAll:
|
case LoopAll:
|
||||||
return "all"
|
return "all"
|
||||||
|
case LoopOne:
|
||||||
|
return "one"
|
||||||
}
|
}
|
||||||
return "UNKNOWN_LOOP_MODE"
|
return "UNKNOWN_LOOP_MODE"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,8 +68,13 @@ func (a *AuxControls) OnChangeLoopMode(f func()) {
|
|||||||
func (a *AuxControls) SetLoopMode(mode string) {
|
func (a *AuxControls) SetLoopMode(mode string) {
|
||||||
if mode == "all" {
|
if mode == "all" {
|
||||||
a.loop.Importance = widget.HighImportance
|
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 {
|
} else {
|
||||||
a.loop.Importance = widget.MediumImportance
|
a.loop.Importance = widget.MediumImportance
|
||||||
|
a.loop.Icon = theme.MediaReplayIcon()
|
||||||
}
|
}
|
||||||
a.loop.Refresh()
|
a.loop.Refresh()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user