Commit 6f20529449

6f20529449b40ee85f5e7a2cb25dd9318c9462b4

parent: 7584ad3c28

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-19 21:06 UTC

Fix: Start mpv handels all

Layout: unified · split

internal/player.go +14 −7
@@ -2,19 +2,26 @@ package internal
2 2
3import ( 3import (
4 // "fmt" 4 // "fmt"
5 "encoding/json"
5 "fmt" 6 "fmt"
6 "os/exec"
7 "encoding/json"
8 "net" 7 "net"
8 "os"
9 "os/exec"
10 "strconv"
9 "time" 11 "time"
10 "os" 12 "math/rand"
11) 13)
12var logFile = "debug.log" 14var logFile = "debug.log"
13 15
14// StartMpv starts the mpv player with the given video URL and IPC socket path. 16// StartMpv starts the mpv player with the given video URL and return ipc socket path.
15func StartMpv(videoURL, socketPath string) error { 17func StartMpv(videoURL string) (string, error) {
16 cmd := exec.Command("mpv", "--input-ipc-server="+socketPath, videoURL) 18 // Generate a random mpvsocket path (Linux only)
17 return cmd.Start() 19 randomNumber := rand.Intn(100) // Change 100 to the desired range
20 fmt.Println("random number", randomNumber)
21 mpvSocketPath := "/tmp/mpvsocket"+strconv.Itoa(randomNumber)
22
23 cmd := exec.Command("mpv", "--input-ipc-server="+mpvSocketPath, videoURL)
24 return mpvSocketPath, cmd.Start()
18} 25}
19 26
20// sendIpcMessage sends a JSON message to the mpv IPC socket and reads the response. 27// sendIpcMessage sends a JSON message to the mpv IPC socket and reads the response.