diff --git a/backend/app.go b/backend/app.go index 47408e2..7f59d9e 100644 --- a/backend/app.go +++ b/backend/app.go @@ -80,7 +80,9 @@ func (a *App) readConfig() { func (a *App) initMPV() error { p := player.NewWithClientName(AppName) - if err := p.Init(a.Config.LocalPlayback.AudioExclusive); err != nil { + c := a.Config.LocalPlayback + c.InMemoryCacheSizeMB = clamp(c.InMemoryCacheSizeMB, 10, 500) + if err := p.Init(c.AudioExclusive, c.InMemoryCacheSizeMB); err != nil { return fmt.Errorf("failed to initialize mpv player: %s", err.Error()) } a.Player = p diff --git a/backend/config.go b/backend/config.go index 0454854..8fddff0 100644 --- a/backend/config.go +++ b/backend/config.go @@ -48,8 +48,9 @@ type PlaylistPageConfig struct { } type LocalPlaybackConfig struct { - AudioExclusive bool - Volume int + AudioExclusive bool + InMemoryCacheSizeMB int + Volume int } type ScrobbleConfig struct { @@ -98,8 +99,9 @@ func DefaultConfig() *Config { TracklistColumns: []string{"Artist", "Album", "Time", "Plays"}, }, LocalPlayback: LocalPlaybackConfig{ - AudioExclusive: false, - Volume: 100, + AudioExclusive: false, + InMemoryCacheSizeMB: 30, + Volume: 100, }, Scrobbling: ScrobbleConfig{ Enabled: true, diff --git a/player/player.go b/player/player.go index 4d119cb..095dd40 100644 --- a/player/player.go +++ b/player/player.go @@ -77,7 +77,7 @@ func NewWithClientName(c string) *Player { // Initializes the Player and makes it ready for playback. // Most Player functions will return ErrUnitialized if called before Init. -func (p *Player) Init(audioExclusive bool) error { +func (p *Player) Init(audioExclusive bool, maxCacheMB int) error { if !p.initialized { m, err := CreateMPV() if err != nil { @@ -91,6 +91,9 @@ func (p *Player) Init(audioExclusive bool) error { m.SetOptionString("force-seekable", "yes") m.SetOptionString("terminal", "no") + // limit in-memory cache size + m.SetOptionString("demuxer-max-bytes", fmt.Sprintf("%dMiB", maxCacheMB)) + if p.vol < 0 { p.vol = 100 }