File: README.md

package info (click to toggle)
golang-github-darkhz-mpvipc 0.0~git20231124.eb73ba4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 112 kB
  • sloc: sh: 6; makefile: 2
file content (74 lines) | stat: -rw-r--r-- 1,961 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# mpvipc
[![GoDoc](https://godoc.org/github.com/DexterLB/mpvipc?status.svg)](http://godoc.org/github.com/DexterLB/mpvipc)
[![Build Status](https://travis-ci.org/DexterLB/mpvipc.svg?branch=master)](https://travis-ci.org/DexterLB/mpvipc)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/DexterLB/mpvipc/master/LICENSE)

A Go implementation of [mpv](http://mpv.io)'s [IPC interface](https://mpv.io/manual/master/#json-ipc)

## Sample usage

* Run mpv

    ```
    $ mpv some_file.mkv --input-unix-socket=/tmp/mpv_socket
    ```

* Do things to it!
    
    ```go
    package main

    import (
        "fmt"
        "log"

        "github.com/DexterLB/mpvipc"
    )

    func main() {
        conn := mpvipc.NewConnection("/tmp/mpv_rpc")
        err := conn.Open()
        if err != nil {
            log.Fatal(err)
        }
        defer conn.Close()

        events, stopListening := conn.NewEventListener()

        path, err := conn.Get("path")
        if err != nil {
            log.Fatal(err)
        }
        log.Printf("current file playing: %s", path)

        err = conn.Set("pause", true)
        if err != nil {
            log.Fatal(err)
        }
        log.Printf("paused!")

        _, err = conn.Call("observe_property", 42, "volume")
        if err != nil {
            fmt.Print(err)
        }

        go func() {
            conn.WaitUntilClosed()
            stopListening <- struct{}{}
        }()

        for event := range events {
            if event.ID == 42 {
                log.Printf("volume now is %f", event.Data.(float64))
            } else {
                log.Printf("received event: %s", event.Name)
            }
        }

        log.Printf("mpv closed socket")
    }
    ```

See more examples at the [documentation](http://godoc.org/github.com/DexterLB/mpvipc).

All of mpv's functions and properties are listed [here](https://mpv.io/manual/master/#json-ipc).