Documentation
¶
Index ¶
- Variables
- func StartAndConnect(ctx context.Context, socketPath string, files ...string) (*Server, *Client, error)
- type Client
- func (c *Client) ClearPlaylist() error
- func (c *Client) Close() error
- func (c *Client) Command(args ...any) (json.RawMessage, error)
- func (c *Client) CommandContext(ctx context.Context, args ...any) (json.RawMessage, error)
- func (c *Client) DroppedEvents() int64
- func (c *Client) Events() <-chan Event
- func (c *Client) GetPlaylist() ([]PlaylistItem, int, error)
- func (c *Client) GetVolume() (float64, error)
- func (c *Client) LoadFile(path string, mode ...string) error
- func (c *Client) Next() error
- func (c *Client) ObserveProperties(properties ...string) error
- func (c *Client) ObserveProperty(id int64, property string) error
- func (c *Client) Pause() error
- func (c *Client) PlayIndex(idx int) error
- func (c *Client) Prev() error
- func (c *Client) RemoveIndex(idx int) error
- func (c *Client) Resume() error
- func (c *Client) SeekAbsolute(seconds float64) error
- func (c *Client) SeekRelative(seconds float64) error
- func (c *Client) Send(args ...any) error
- func (c *Client) SetMute(mute bool) error
- func (c *Client) SetVolume(volume float64) error
- func (c *Client) Shuffle() error
- func (c *Client) Stop() error
- func (c *Client) ToggleMute() error
- func (c *Client) TogglePause() error
- type Event
- type EventType
- type PlaylistItem
- type Server
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClosed is returned when an operation is performed on a closed client. ErrClosed = errors.New("gompv: connection closed") // ErrTimeout is returned when a command response exceeds its deadline. ErrTimeout = errors.New("gompv: request timeout") )
var DefaultObservedProperties = []string{
"pause",
"time-pos",
"duration",
"media-title",
"volume",
"mute",
"playlist-pos",
"playlist-count",
"eof-reached",
"idle-active",
}
DefaultObservedProperties contains the common properties observed by media players.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client handles concurrent-safe IPC communication over an mpv Unix socket.
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) ClearPlaylist ¶ added in v0.3.0
ClearPlaylist removes all entries from the playlist.
func (*Client) Close ¶
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 ¶
CommandContext sends a synchronous JSON command respecting the provided context.
func (*Client) DroppedEvents ¶
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) LoadFile ¶ added in v0.3.0
LoadFile appends or replaces a file in the playlist. Mode can be "replace", "append", or "append-play". Defaults to "replace".
func (*Client) ObserveProperties ¶
ObserveProperties registers change notifications for the given properties. If no properties are provided, DefaultObservedProperties will be observed.
func (*Client) ObserveProperty ¶ added in v0.3.0
ObserveProperty registers an individual property change notification with mpv.
func (*Client) RemoveIndex ¶
RemoveIndex removes a track from the playlist by its index.
func (*Client) SeekAbsolute ¶ added in v0.3.0
SeekAbsolute performs an absolute seek to the specified timestamp in seconds.
func (*Client) SeekRelative ¶
SeekRelative performs a relative seek by the specified number of seconds.
func (*Client) Send ¶ added in v0.1.1
Send writes an asynchronous JSON command without waiting for a response.
func (*Client) ToggleMute ¶ added in v0.3.0
ToggleMute toggles mute state.
func (*Client) TogglePause ¶
TogglePause toggles playback state between pause and play.
type Event ¶ added in v0.2.0
Event encapsulates an mpv event with helper methods to avoid manual type assertions.
func (Event) PropertyBool ¶ added in v0.2.3
PropertyBool safely extracts the value of a boolean property.
func (Event) PropertyChange ¶ added in v0.2.0
PropertyChange extracts the property name and its value if the event is a property-change.
func (Event) PropertyFloat ¶ added in v0.2.3
PropertyFloat safely extracts the value of a numeric property as a float64.
type EventType ¶ added in v0.2.0
type EventType string
EventType represents the type of event received from mpv.
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 ¶
StartServer removes any stale socket if it exists and launches mpv in background IPC mode.