mpv

package module
v0.0.0-...-2234366 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2020 License: MIT Imports: 10 Imported by: 0

README

mpv (remote) control library

This library provides everything needed to (remote) control the mpv media player.

It provides an easy api, a json api and rpc functionality.

Usecases: Remote control your mediaplayer running on a raspberry pi or laptop or build a http interface for mpv

Usage

$ go get github.com/blang/mpv

Note: Always vendor your dependencies or fix on a specific version tag.

Start mpv:

$ mpv --idle --input-ipc-server=/tmp/mpvsocket

Remote control:

import github.com/blang/mpv

ipcc := mpv.NewIPCClient("/tmp/mpvsocket") // Lowlevel client
c := mpv.NewClient(ipcc) // Highlevel client, can also use RPCClient

c.LoadFile("movie.mp4", mpv.LoadFileModeReplace)
c.SetPause(true)
c.Seek(600, mpv.SeekModeAbsolute)
c.SetFullscreen(true)
c.SetPause(false)

pos, err := c.Position()
fmt.Printf("Position in Seconds: %.0f", pos)

Also check the GoDocs.

Features

  • Low-Level and High-Level API
  • RPC Server and Client (fully transparent)
  • HTTP Handler exposing lowlevel API (json)

Contribution

Feel free to make a pull request. For bigger changes create a issue first to discuss about it.

License

See LICENSE file.

Documentation

Index

Constants

View Source
const (
	SeekModeRelative = "relative"
	SeekModeAbsolute = "absolute"
)

Variables

View Source
var (
	ErrTimeoutSend = errors.New("timeout while sending command")
	ErrTimeoutRecv = errors.New("timeout while receiving response")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a more comfortable higher level interface to LLClient. It can use any LLClient implementation.

func NewClient

func NewClient(socket string) (*Client, error)

NewClient creates a new highlevel client based on a lowlevel client.

func (*Client) Exec

func (c *Client) Exec(command ...interface{}) (*Response, error)

func (*Client) GetBoolProperty

func (c *Client) GetBoolProperty(name string) (bool, error)

GetBoolProperty reads a bool property and returns the data as a boolean.

func (*Client) GetFloatProperty

func (c *Client) GetFloatProperty(name string) (float64, error)

GetFloatProperty reads a float property and returns the data as a float64.

func (*Client) GetProperty

func (c *Client) GetProperty(name string) (string, error)

GetProperty reads a property by name and returns the data as a string.

func (*Client) LoadFile

func (c *Client) LoadFile(path string) error

func (*Client) Mute

func (c *Client) Mute() (bool, error)

func (*Client) ObserveFloat

func (c *Client) ObserveFloat(property string, cb func(value float64))

func (*Client) ObserveString

func (c *Client) ObserveString(property string, cb func(value string))

func (*Client) Pause

func (c *Client) Pause() (bool, error)

func (*Client) Seek

func (c *Client) Seek(n int, mode string) error

func (*Client) SetMute

func (c *Client) SetMute(mute bool) error

SetMute mutes or unmutes the player.

func (*Client) SetPause

func (c *Client) SetPause(pause bool) error

func (*Client) SetProperty

func (c *Client) SetProperty(name string, value interface{}) error

SetProperty sets the value of a property.

type Response

type Response struct {
	Err       string      `json:"error"`
	Data      interface{} `json:"data"` // May contain float64, bool or string
	Event     string      `json:"event"`
	RequestID int         `json:"request_id"`
	Name      string      `json:"name"`
}

Response received from mpv. Can be an event or a user requested response.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL