gompv

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 14 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 launches mpv and establishes a connection using retry logic.

Types

type Client

type Client struct {
	Events chan Event
	// contains filtered or unexported fields
}

Client handles concurrent-safe IPC communication over an mpv Unix socket.

func Connect

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

Connect dials the given socket path and initializes the background read loop.

func ConnectWithRetry

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

ConnectWithRetry repeatedly attempts to connect until the socket appears or context is canceled.

func (*Client) Close

func (c *Client) Close() error

Close gracefully shuts down the client connection and cleans up pending requests.

func (*Client) Command

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

Command sends a synchronous JSON command and blocks until a response is received.

func (*Client) CommandContext

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

CommandContext sends a synchronous JSON command respecting the provided context.

func (*Client) DroppedEvents

func (c *Client) DroppedEvents() int64

DroppedEvents returns the count of events dropped due to a full buffer.

func (*Client) GetPlaylist

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

GetPlaylist queries the current playlist and returns the active track index (-1 if none).

func (*Client) ObserveProperties

func (c *Client) ObserveProperties() error

ObserveProperties registers property change notifications required by the TUI client.

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 performs a relative seek by the specified number of seconds.

func (*Client) Send added in v0.1.1

func (c *Client) Send(args ...any) error

Send writes an asynchronous JSON command without waiting for a response.

func (*Client) Shuffle

func (c *Client) Shuffle() error

Shuffle randomizes the order of tracks in the playlist.

func (*Client) TogglePause

func (c *Client) TogglePause() error

TogglePause toggles the playback state between pause and play.

type Event added in v0.2.0

type Event struct {
	Type string
	Raw  map[string]any
}

Event encapsulates an mpv event with helper methods to avoid manual type assertions.

func (Event) PropertyChange added in v0.2.0

func (e Event) PropertyChange() (string, any, bool)

PropertyChange extracts the property name and its value if the event is a property-change.

type EventType added in v0.2.0

type EventType string

EventType represents the type of event received from mpv.

const (
	EventPropertyChange EventType = "property-change"
	EventEndFile        EventType = "end-file"
	EventStartFile      EventType = "start-file"
	EventIdle           EventType = "idle"
)

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 lifecycle.

func StartServer

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

StartServer removes any stale socket if it exists and launches mpv in background IPC mode.

func (*Server) Stop

func (s *Server) Stop()

Stop terminates the mpv process cleanly with timeout fallback and removes the socket file.

func (*Server) Wait

func (s *Server) Wait() error

Wait blocks until the underlying mpv process terminates.

Jump to

Keyboard shortcuts

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