gompv

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartAndConnect

func StartAndConnect(ctx context.Context, socketPath string, files ...string) (*Server, *Client, error)

StartAndConnect is a convenience helper that launches mpv and connects to it using ConnectWithRetry.

Types

type Client

type Client struct {
	Events chan map[string]any
	// contains filtered or unexported fields
}

Client is a concurrent-safe mpv IPC client over a Unix socket.

func Connect

func Connect(socketPath string) (*Client, error)

Connect dials the given Unix socket and starts the background readLoop.

func ConnectWithRetry

func ConnectWithRetry(ctx context.Context, socketPath string, interval time.Duration) (*Client, error)

ConnectWithRetry keeps trying until the socket appears or the context is cancelled.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the client. Safe to call multiple times.

func (*Client) Command

func (c *Client) Command(args ...any) (json.RawMessage, error)

Command sends a JSON command and waits for the matching response.

func (*Client) CommandContext

func (c *Client) CommandContext(ctx context.Context, args ...any) (json.RawMessage, error)

CommandContext sends a JSON command respecting the provided context.

func (*Client) Done

func (c *Client) Done() <-chan struct{}

Done returns a channel that is closed when the underlying connection dies.

func (*Client) DroppedEvents

func (c *Client) DroppedEvents() int64

DroppedEvents returns the number of events discarded because the Events channel buffer was full.

func (*Client) GetPlaylist

func (c *Client) GetPlaylist() ([]PlaylistItem, int, error)

GetPlaylist retrieves the current playlist and returns the index of the active item (-1 if none).

func (*Client) ObserveProperties

func (c *Client) ObserveProperties() error

ObserveProperties registers properties required for a music application or TUI.

func (*Client) PlayIndex

func (c *Client) PlayIndex(idx int) error

PlayIndex switches playback to the specified playlist index.

func (*Client) RemoveIndex

func (c *Client) RemoveIndex(idx int) error

RemoveIndex removes a track from the playlist by its index.

func (*Client) SeekRelative

func (c *Client) SeekRelative(seconds float64) error

SeekRelative seeks forward or backward by the specified number of seconds.

func (*Client) Shuffle

func (c *Client) Shuffle() error

Shuffle shuffles the tracks in the current playlist.

func (*Client) TogglePause

func (c *Client) TogglePause() error

TogglePause toggles between pause and play states.

type PlaylistItem

type PlaylistItem struct {
	Filename string `json:"filename"`
	Title    string `json:"title"`
	Current  bool   `json:"current"`
	Playing  bool   `json:"playing"`
}

PlaylistItem represents an entry within the mpv playlist.

func (PlaylistItem) DisplayName

func (p PlaylistItem) DisplayName() string

DisplayName returns the metadata title or, if unavailable, the base file name.

type Server

type Server struct {
	SocketPath string
	// contains filtered or unexported fields
}

Server manages the background mpv process.

func StartServer

func StartServer(socketPath string, files ...string) (*Server, error)

StartServer removes any stale socket if it exists and launches mpv without a graphical user interface.

func (*Server) Stop

func (s *Server) Stop()

Stop terminates the mpv process cleanly and removes the socket file.

func (*Server) Wait

func (s *Server) Wait() error

Wait blocks until the mpv process terminates.

Jump to

Keyboard shortcuts

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