This is a Go package that provides an interface to the IPC mechanism of the mpv media player.
To install the package, run:
go get github.com/xoltia/mpv
The package requires that the mpv
executable is installed on the system and in the PATH, or
for the location of mpv to be provided using ProcessOptions
.
Check the documentation for more information. For specific commands and properties not directly implemented, see the mpv IPC documentation and make use of the command and property functions directly.
Here is a simple example of playing a video:
package main
import (
"fmt"
"github.com/xoltia/mpv"
)
func main() {
m := mpv.NewProcess()
defer m.Close()
c, err := m.OpenClient()
if err != nil {
panic(err)
}
defer c.Close()
err = c.LoadFile("https://youtu.be/6BfKzQzBe7M", mpv.LoadFileModeReplace)
if err != nil {
panic(err)
}
err = c.Play()
if err != nil {
panic(err)
}
select {}
}
Note
This example also requires that yt-dlp is installed on the system.
For a more complete example, see the example directory.
An IPC connection can be opened with an existing mpv process by
using the OpenClient
function directly.