From 0cd58cb51b2fe5d7c3d91636fd4f5ce2dd4ba894 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Thu, 21 Dec 2023 20:25:44 -0800 Subject: [PATCH] start of new simplified player interface --- player/mpv/player.go | 13 +++++++++++++ player/player.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/player/mpv/player.go b/player/mpv/player.go index 02f4f87..9d99885 100644 --- a/player/mpv/player.go +++ b/player/mpv/player.go @@ -193,6 +193,19 @@ func (p *Player) ClearPlayQueue() error { return p.mpv.Command([]string{"playlist-clear"}) } +func (p *Player) SetFile(url string) error { + if !p.initialized { + return ErrUnitialized + } + if err := p.mpv.Command([]string{"stop"}); err != nil { + return err + } + if err := p.mpv.Command([]string{"playlist-clear"}); err != nil { + return err + } + return p.mpv.Command([]string{"loadfile", url, "append"}) +} + // Seeks within the currently playing track. // See MPV seek command documentation for more details. func (p *Player) SeekSeconds(secs float64) error { diff --git a/player/player.go b/player/player.go index b734f07..a862715 100644 --- a/player/player.go +++ b/player/player.go @@ -7,11 +7,23 @@ type URLPlayer interface { AppendFile(url string) error } +type URLPlayerNew interface { + BasePlayer + SetFile(url string) + SetNextFile(url string) +} + type TrackPlayer interface { BasePlayer AppendTrack(track *mediaprovider.Track) error } +type TrackPlayerNew interface { + BasePlayer + SetTrack(track *mediaprovider.Track) error + SetNextTrack(track *mediaprovider.Track) error +} + type BasePlayer interface { // Transport PlayTrackAt(idx int) error @@ -42,6 +54,27 @@ type BasePlayer interface { OnTrackChange(func(int)) } +type BasePlayerNew interface { + Continue() error + Pause() error + Stop() error + + SeekSeconds(secs float64) error + IsSeeking() bool + + SetVolume(int) error + GetVolume() int + + GetStatus() Status + + // Event API + OnPaused(func()) + OnStopped(func()) + OnPlaying(func()) + OnSeek(func()) + OnTrackChange(func(int)) +} + type ReplayGainPlayer interface { SetReplayGainOptions(ReplayGainOptions) error }