Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
3e68bbda29 | |||
bca0e0bf3a | |||
4fef37ceca | |||
0e44626c13 |
15
commands.go
15
commands.go
@ -2,7 +2,6 @@ package mpvipc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,21 +29,29 @@ func Quit(socket string) error {
|
|||||||
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)
|
||||||
|
|
||||||
|
if Ping(socket) {
|
||||||
|
out <- true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ticker := time.NewTicker(100 * time.Millisecond)
|
ticker := time.NewTicker(100 * time.Millisecond)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
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
8
playlist_entry.go
Normal 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"`
|
||||||
|
}
|
@ -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 SetPlaylistPosition(socket string, index int) error {
|
||||||
|
return SetProperty(socket, "playlist-pos", index)
|
||||||
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
Reference in New Issue
Block a user