Commit 6f20529449
Unsigned
Layout: unified · split
internal/player.go +14 −7
| @@ -2,19 +2,26 @@ package internal | ||
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | 4 | // "fmt" |
| 5 | "encoding/json" | |
| 5 | 6 | "fmt" |
| 6 | "os/exec" | |
| 7 | "encoding/json" | |
| 8 | 7 | "net" |
| 8 | "os" | |
| 9 | "os/exec" | |
| 10 | "strconv" | |
| 9 | 11 | "time" |
| 10 | "os" | |
| 12 | "math/rand" | |
| 11 | 13 | ) |
| 12 | 14 | var logFile = "debug.log" |
| 13 | 15 | |
| 14 | // StartMpv starts the mpv player with the given video URL and IPC socket path. | |
| 15 | func StartMpv(videoURL, socketPath string) error { | |
| 16 | cmd := exec.Command("mpv", "--input-ipc-server="+socketPath, videoURL) | |
| 17 | return cmd.Start() | |
| 16 | // StartMpv starts the mpv player with the given video URL and return ipc socket path. | |
| 17 | func StartMpv(videoURL string) (string, error) { | |
| 18 | // Generate a random mpvsocket path (Linux only) | |
| 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 | 27 | // sendIpcMessage sends a JSON message to the mpv IPC socket and reads the response. |