limit MPV in-memory cache size and make it configurable

This commit is contained in:
Drew Weymouth
2023-03-28 17:34:39 -07:00
parent d67dfa07b3
commit 0a11df8c07
3 changed files with 13 additions and 6 deletions
+4 -1
View File
@@ -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
}