Skip to content

Commit

Permalink
bug(core/playback/mpv): jukebox mode under windows - navidrome#2767
Browse files Browse the repository at this point in the history
Use named pipe for socket path under windows during mpv playback, change function name, unexport function

Signed-off-by: apkatsikas <apkatsikas@gmail.com>
  • Loading branch information
apkatsikas committed Jan 7, 2024
1 parent 6f7b482 commit eb65688
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions core/playback/mpv/mpv.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"sync"

Expand Down Expand Up @@ -134,9 +135,16 @@ var (
mpvErr error
)

func TempFileName(prefix, suffix string) string {
func randomSocketName(prefix, suffix string) string {
randBytes := make([]byte, 16)
// we can savely ignore the return value since we're loading into a precreated, fixedsized buffer
// we can saely ignore the return value since we're loading into a precreated, fixedsized buffer
_, _ = rand.Read(randBytes)
return filepath.Join(os.TempDir(), prefix+hex.EncodeToString(randBytes)+suffix)

socketPath := os.TempDir()
// Windows needs to use a named pipe instead of a file for the socket
// see https://mpv.io/manual/master#using-mpv-from-other-programs-or-scripts
if runtime.GOOS == "windows" {
socketPath = `\\.\pipe\mpvsocket`
}
return filepath.Join(socketPath, prefix+hex.EncodeToString(randBytes)+suffix)
}
2 changes: 1 addition & 1 deletion core/playback/mpv/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewTrack(playbackDoneChannel chan bool, deviceName string, mf model.MediaFi
return nil, err
}

tmpSocketName := TempFileName("mpv-ctrl-", ".socket")
tmpSocketName := randomSocketName("mpv-ctrl-", ".socket")

args := createMPVCommand(mpvComdTemplate, deviceName, mf.Path, tmpSocketName)
exe, err := start(args)
Expand Down

0 comments on commit eb65688

Please sign in to comment.