8 Commits

Author SHA1 Message Date
e5f6becf97 removed GetPause double 2025-08-30 14:18:39 +02:00
86c9dc0cc5 added GetLoopFile and GetLoopPlaylist 2025-08-30 14:16:13 +02:00
e425b08ef8 added ShufflePlaylist 2025-06-28 15:33:45 +02:00
f413f97824 added GetPlaylistPosition 2025-06-28 14:18:56 +02:00
5eb15eb7a5 GetPause implemented 2025-06-28 14:14:55 +02:00
3e68bbda29 added SetPlaylistPosition 2025-06-28 13:47:16 +02:00
bca0e0bf3a added GetPlaylist() 2025-06-28 13:36:09 +02:00
4fef37ceca introduced Ping() function 2025-06-28 13:17:11 +02:00
4 changed files with 47 additions and 13 deletions

View File

@ -2,7 +2,6 @@ package mpvipc
import ( import (
"context" "context"
"net"
"time" "time"
) )
@ -24,21 +23,30 @@ func LoadFile(socket string, file string, flags LoadFileFlag) error {
return err return err
} }
func ShufflePlaylist(socket string) error {
cmd := &Command{Command: []interface{}{"playlist-shuffle"}}
_, err := SendCommand[any](socket, cmd)
return err
}
func Quit(socket string) error { func Quit(socket string) error {
cmd := &Command{Command: []interface{}{"quit"}} cmd := &Command{Command: []interface{}{"quit"}}
_, err := SendCommand[any](socket, cmd) _, err := SendCommand[any](socket, cmd)
return err return err
} }
func Ping(socket string) bool {
_, err := GetPID(socket)
return err == nil
}
func IsReady(ctx context.Context, socket string) <-chan bool { func IsReady(ctx context.Context, socket string) <-chan bool {
out := make(chan bool, 1) out := make(chan bool, 1)
go func() { go func() {
defer close(out) defer close(out)
conn, err := net.Dial("unix", socket) if Ping(socket) {
if err == nil {
defer conn.Close()
out <- true out <- true
return return
} }
@ -49,9 +57,7 @@ func IsReady(ctx context.Context, socket string) <-chan bool {
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
conn, err := net.Dial("unix", socket) if Ping(socket) {
if err == nil {
defer conn.Close()
out <- true out <- true
return return
} }

8
playlist_entry.go Normal file
View File

@ -0,0 +1,8 @@
package mpvipc
type PlaylistEntry struct {
Filename string `json:"filename"`
Current bool `json:"current"`
Playing bool `json:"playing"`
ID int `json:"id"`
}

View File

@ -9,11 +9,11 @@ func GetDisplayNames(socket string) ([]string, error) {
return GetProperty[[]string](socket, "display-names") return GetProperty[[]string](socket, "display-names")
} }
func IsFullscreen(socket string) (bool, error) { func GetFullscreen(socket string) (bool, error) {
return GetProperty[bool](socket, "fullscreen") return GetProperty[bool](socket, "fullscreen")
} }
func IsPaused(socket string) (bool, error) { func GetPaused(socket string) (bool, error) {
return GetProperty[bool](socket, "pause") return GetProperty[bool](socket, "pause")
} }
@ -49,6 +49,14 @@ func GetFileFormat(socket string) (string, error) {
return GetProperty[string](socket, "file-format") return GetProperty[string](socket, "file-format")
} }
func GetPlaylist(socket string) ([]PlaylistEntry, error) {
return GetProperty[[]PlaylistEntry](socket, "playlist")
}
func GetPlaylistPosition(socket string) (int, error) {
return GetProperty[int](socket, "playlist-pos")
}
func GetDuration(socket string) (time.Duration, error) { func GetDuration(socket string) (time.Duration, error) {
durationInSeconds, err := GetProperty[float64](socket, "duration") durationInSeconds, err := GetProperty[float64](socket, "duration")
if err != nil { if err != nil {
@ -89,7 +97,7 @@ func GetTimeRemaining(socket string) (time.Duration, error) {
return time.Duration(durationInSeconds * float64(time.Second)), nil return time.Duration(durationInSeconds * float64(time.Second)), nil
} }
func IsSeeking(socket string) (bool, error) { func GetSeeking(socket string) (bool, error) {
return GetProperty[bool](socket, "seeking") return GetProperty[bool](socket, "seeking")
} }
@ -133,18 +141,26 @@ func GetChapterList(socket string) ([]Chapter, error) {
return GetProperty[[]Chapter](socket, "chapter-list") return GetProperty[[]Chapter](socket, "chapter-list")
} }
func IsSeekable(socket string) (bool, error) { func GetSeekable(socket string) (bool, error) {
return GetProperty[bool](socket, "seekable") return GetProperty[bool](socket, "seekable")
} }
func IsPartiallySeekable(socket string) (bool, error) { func GetPartiallySeekable(socket string) (bool, error) {
return GetProperty[bool](socket, "partially-seekable") return GetProperty[bool](socket, "partially-seekable")
} }
func IsPlaybackAborted(socket string) (bool, error) { func GetPlaybackAborted(socket string) (bool, error) {
return GetProperty[bool](socket, "playback-abort") return GetProperty[bool](socket, "playback-abort")
} }
func GetPropertyList(socket string) ([]string, error) { func GetPropertyList(socket string) ([]string, error) {
return GetProperty[[]string](socket, "property-list") return GetProperty[[]string](socket, "property-list")
} }
func GetLoopFile(socket string) (bool, error) {
return GetProperty[bool](socket, "loop-file")
}
func GetLoopPlaylist(socket string) (bool, error) {
return GetProperty[bool](socket, "loop-playlist")
}

View File

@ -21,3 +21,7 @@ func SetPercentPos(socket string, percentPos float64) error {
func SetVolume(socket string, volume float64) error { func SetVolume(socket string, volume float64) error {
return SetProperty[float64](socket, "volume", volume) return SetProperty[float64](socket, "volume", volume)
} }
func SetPlaylistPosition(socket string, index int) error {
return SetProperty(socket, "playlist-pos", index)
}