Refactor pt. 1: move MPV player to own package and extract some types
This commit is contained in:
+12
-5
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/dweymouth/supersonic/backend/util"
|
||||
"github.com/dweymouth/supersonic/player"
|
||||
"github.com/dweymouth/supersonic/player/mpv"
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/google/uuid"
|
||||
@@ -36,7 +37,7 @@ type App struct {
|
||||
ServerManager *ServerManager
|
||||
ImageManager *ImageManager
|
||||
PlaybackManager *PlaybackManager
|
||||
Player *player.Player
|
||||
Player *mpv.Player
|
||||
UpdateChecker UpdateChecker
|
||||
MPRISHandler *MPRISHandler
|
||||
|
||||
@@ -194,7 +195,7 @@ func (a *App) callOnReactivate() {
|
||||
}
|
||||
|
||||
func (a *App) initMPV() error {
|
||||
p := player.NewWithClientName(a.appName)
|
||||
p := mpv.NewWithClientName(a.appName)
|
||||
c := a.Config.LocalPlayback
|
||||
c.InMemoryCacheSizeMB = clamp(c.InMemoryCacheSizeMB, 10, 500)
|
||||
if err := p.Init(c.InMemoryCacheSizeMB); err != nil {
|
||||
@@ -234,10 +235,16 @@ func (a *App) setupMPV() error {
|
||||
if !sharedutil.SliceContains(rgainOpts, a.Config.ReplayGain.Mode) {
|
||||
a.Config.ReplayGain.Mode = ReplayGainNone
|
||||
}
|
||||
mode := player.ReplayGainMode(a.Config.ReplayGain.Mode)
|
||||
if a.Config.ReplayGain.Mode == ReplayGainAuto {
|
||||
mode := player.ReplayGainNone
|
||||
switch a.Config.ReplayGain.Mode {
|
||||
case ReplayGainAlbum:
|
||||
mode = player.ReplayGainAlbum
|
||||
case ReplayGainTrack:
|
||||
mode = player.ReplayGainTrack
|
||||
case ReplayGainAuto:
|
||||
mode = player.ReplayGainTrack
|
||||
}
|
||||
|
||||
a.Player.SetReplayGainOptions(player.ReplayGainOptions{
|
||||
Mode: mode,
|
||||
PreventClipping: a.Config.ReplayGain.PreventClipping,
|
||||
@@ -245,7 +252,7 @@ func (a *App) setupMPV() error {
|
||||
})
|
||||
a.Player.SetAudioExclusive(a.Config.LocalPlayback.AudioExclusive)
|
||||
|
||||
eq := &player.ISO15BandEqualizer{
|
||||
eq := &mpv.ISO15BandEqualizer{
|
||||
EQPreamp: a.Config.LocalPlayback.EqualizerPreamp,
|
||||
Disabled: !a.Config.LocalPlayback.EqualizerEnabled,
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/player"
|
||||
"github.com/dweymouth/supersonic/player/mpv"
|
||||
)
|
||||
|
||||
// os_remote_command_callback is called by Objective-C when incoming OS media commands are received.
|
||||
@@ -51,7 +52,7 @@ func os_remote_command_callback(command C.Command, value C.double) {
|
||||
|
||||
// MPMediaHandler is the handler for MacOS media controls and system events.
|
||||
type MPMediaHandler struct {
|
||||
player *player.Player
|
||||
player *mpv.Player
|
||||
playbackManager *PlaybackManager
|
||||
artURLLookup func(string) (string, error)
|
||||
}
|
||||
@@ -62,7 +63,7 @@ var mpMediaEventRecipient *MPMediaHandler
|
||||
|
||||
// NewMPMediaHandler creates a new MPMediaHandler instances and sets it as the current recipient
|
||||
// for incoming system events.
|
||||
func InitMPMediaHandler(player *player.Player, playbackManager *PlaybackManager, artURLLookup func(trackID string) (string, error)) error {
|
||||
func InitMPMediaHandler(player *mpv.Player, playbackManager *PlaybackManager, artURLLookup func(trackID string) (string, error)) error {
|
||||
mp := &MPMediaHandler{
|
||||
player: player,
|
||||
playbackManager: playbackManager,
|
||||
@@ -187,5 +188,5 @@ func (mp *MPMediaHandler) OnCommandSeek(positionSeconds float64) {
|
||||
if mp == nil || mp.player == nil {
|
||||
return
|
||||
}
|
||||
mp.player.Seek(fmt.Sprintf("%0.2f", positionSeconds), player.SeekAbsolute)
|
||||
mp.player.Seek(fmt.Sprintf("%0.2f", positionSeconds), mpv.SeekAbsolute)
|
||||
}
|
||||
|
||||
+5
-5
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/player"
|
||||
"github.com/dweymouth/supersonic/player/mpv"
|
||||
"github.com/godbus/dbus/v5"
|
||||
"github.com/quarckster/go-mpris-server/pkg/events"
|
||||
"github.com/quarckster/go-mpris-server/pkg/server"
|
||||
@@ -43,13 +44,13 @@ type MPRISHandler struct {
|
||||
connErr error
|
||||
playerName string
|
||||
curTrackPath string // empty for no track
|
||||
p *player.Player
|
||||
p *mpv.Player
|
||||
pm *PlaybackManager
|
||||
s *server.Server
|
||||
evt *events.EventHandler
|
||||
}
|
||||
|
||||
func NewMPRISHandler(playerName string, p *player.Player, pm *PlaybackManager) *MPRISHandler {
|
||||
func NewMPRISHandler(playerName string, p *mpv.Player, pm *PlaybackManager) *MPRISHandler {
|
||||
m := &MPRISHandler{playerName: playerName, p: p, pm: pm, connErr: errors.New("not started")}
|
||||
m.s = server.NewServer(playerName, m, m)
|
||||
m.evt = events.NewEventHandler(m.s)
|
||||
@@ -180,12 +181,12 @@ func (m *MPRISHandler) Play() error {
|
||||
}
|
||||
|
||||
func (m *MPRISHandler) Seek(offset types.Microseconds) error {
|
||||
return m.p.Seek(fmt.Sprintf("%0.2f", microsecondsToSeconds(offset)), player.SeekRelative)
|
||||
return m.p.Seek(fmt.Sprintf("%0.2f", microsecondsToSeconds(offset)), mpv.SeekRelative)
|
||||
}
|
||||
|
||||
func (m *MPRISHandler) SetPosition(trackId string, position types.Microseconds) error {
|
||||
if m.curTrackPath == trackId {
|
||||
return m.p.Seek(fmt.Sprintf("%0.2f", microsecondsToSeconds(position)), player.SeekAbsolute)
|
||||
return m.p.Seek(fmt.Sprintf("%0.2f", microsecondsToSeconds(position)), mpv.SeekAbsolute)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -326,4 +327,3 @@ func encodeTrackId(id string) string {
|
||||
data := []byte(id)
|
||||
return base32.StdEncoding.WithPadding('0').EncodeToString(data)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,14 @@ import (
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/backend/util"
|
||||
"github.com/dweymouth/supersonic/player"
|
||||
"github.com/dweymouth/supersonic/player/mpv"
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
)
|
||||
|
||||
const (
|
||||
ReplayGainNone = string(player.ReplayGainNone)
|
||||
ReplayGainAlbum = string(player.ReplayGainAlbum)
|
||||
ReplayGainTrack = string(player.ReplayGainTrack)
|
||||
var (
|
||||
ReplayGainNone = player.ReplayGainNone.String()
|
||||
ReplayGainAlbum = player.ReplayGainAlbum.String()
|
||||
ReplayGainTrack = player.ReplayGainTrack.String()
|
||||
ReplayGainAuto = "Auto"
|
||||
)
|
||||
|
||||
@@ -34,7 +35,7 @@ type PlaybackManager struct {
|
||||
cancelPollPos context.CancelFunc
|
||||
pollingTick *time.Ticker
|
||||
sm *ServerManager
|
||||
player *player.Player
|
||||
player *mpv.Player
|
||||
|
||||
playTimeStopwatch util.Stopwatch
|
||||
curTrackTime float64
|
||||
@@ -59,7 +60,7 @@ type PlaybackManager struct {
|
||||
func NewPlaybackManager(
|
||||
ctx context.Context,
|
||||
s *ServerManager,
|
||||
p *player.Player,
|
||||
p *mpv.Player,
|
||||
scrobbleCfg *ScrobbleConfig,
|
||||
transcodeCfg *TranscodingConfig,
|
||||
) *PlaybackManager {
|
||||
@@ -335,7 +336,16 @@ func (p *PlaybackManager) StopAndClearPlayQueue() {
|
||||
|
||||
func (p *PlaybackManager) SetReplayGainOptions(config ReplayGainConfig) {
|
||||
p.replayGainCfg = config
|
||||
mode := player.ReplayGainMode(config.Mode)
|
||||
mode := player.ReplayGainNone
|
||||
switch config.Mode {
|
||||
case ReplayGainAuto:
|
||||
mode = player.ReplayGainTrack
|
||||
case ReplayGainTrack:
|
||||
mode = player.ReplayGainTrack
|
||||
case ReplayGainAlbum:
|
||||
mode = player.ReplayGainAlbum
|
||||
}
|
||||
|
||||
if config.Mode == ReplayGainAuto {
|
||||
mode = player.ReplayGainTrack
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user