Compare commits
No commits in common. "main" and "v0.0.2" have entirely different histories.
40
commands.go
40
commands.go
@ -1,11 +1,5 @@
|
|||||||
package mpvipc
|
package mpvipc
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type LoadFileFlag string
|
type LoadFileFlag string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -23,37 +17,3 @@ func LoadFile(socket string, file string, flags LoadFileFlag) error {
|
|||||||
_, err := SendCommand[any](socket, cmd)
|
_, err := SendCommand[any](socket, cmd)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Quit(socket string) error {
|
|
||||||
cmd := &Command{Command: []interface{}{"quit"}}
|
|
||||||
_, err := SendCommand[any](socket, cmd)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsReady(ctx context.Context, socket string) <-chan bool {
|
|
||||||
out := make(chan bool, 1)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer close(out)
|
|
||||||
|
|
||||||
ticker := time.NewTicker(100 * time.Millisecond)
|
|
||||||
defer ticker.Stop()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ticker.C:
|
|
||||||
conn, err := net.Dial("unix", socket)
|
|
||||||
if err == nil {
|
|
||||||
defer conn.Close()
|
|
||||||
out <- true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case <-ctx.Done():
|
|
||||||
out <- false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
13
props_get.go
13
props_get.go
@ -17,10 +17,6 @@ func IsPaused(socket string) (bool, error) {
|
|||||||
return GetProperty[bool](socket, "pause")
|
return GetProperty[bool](socket, "pause")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetVolume(socket string) (float64, error) {
|
|
||||||
return GetProperty[float64](socket, "volume")
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetFilename(socket string) (string, error) {
|
func GetFilename(socket string) (string, error) {
|
||||||
return GetProperty[string](socket, "filename")
|
return GetProperty[string](socket, "filename")
|
||||||
}
|
}
|
||||||
@ -58,15 +54,6 @@ func GetDuration(socket string) (time.Duration, error) {
|
|||||||
return time.Duration(durationInSeconds * float64(time.Second)), nil
|
return time.Duration(durationInSeconds * float64(time.Second)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDemuxerCacheTime(socket string) (time.Duration, error) {
|
|
||||||
cacheInSeconds, err := GetProperty[float64](socket, "demuxer-cache-time")
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return time.Duration(cacheInSeconds * float64(time.Second)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetPercentPos(socket string) (float64, error) {
|
func GetPercentPos(socket string) (float64, error) {
|
||||||
return GetProperty[float64](socket, "percent-pos")
|
return GetProperty[float64](socket, "percent-pos")
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,3 @@ func SetTimePos(socket string, timePos time.Duration) error {
|
|||||||
func SetPercentPos(socket string, percentPos float64) error {
|
func SetPercentPos(socket string, percentPos float64) error {
|
||||||
return SetProperty[float64](socket, "percent-pos", percentPos)
|
return SetProperty[float64](socket, "percent-pos", percentPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetVolume(socket string, volume float64) error {
|
|
||||||
return SetProperty[float64](socket, "volume", volume)
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user