player

package
v0.3.28 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package player provides media playback functionality using external players. It supports playing single files or multiple files as a playlist using mpv.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultPath

func GetDefaultPath() string

GetDefaultPath returns the default MPV path for the current platform.

func IsAvailable

func IsAvailable(mpvPath string) bool

IsAvailable checks if MPV is available on the system. This is a convenience function for checking availability.

func Play

func Play(streamURL, mpvPath string) error

Play launches MPV to play the given URL. This is a convenience function that uses the default player.

func PlayMultiple

func PlayMultiple(streamURLs []string, mpvPath string) error

PlayMultiple launches MPV to play multiple URLs sequentially. This is a convenience function that uses the default player.

Types

type MPVPlayer added in v0.2.2

type MPVPlayer struct {
	// Path is the path to the mpv executable. If empty, "mpv" is used.
	Path string
}

MPVPlayer implements the Player interface using mpv media player. It provides high-quality media playback with seeking support.

func NewMPVPlayer added in v0.2.2

func NewMPVPlayer(path string) *MPVPlayer

NewMPVPlayer creates a new MPVPlayer with the specified path. If path is empty, the system PATH will be searched for mpv.

func (*MPVPlayer) IsAvailable added in v0.2.2

func (p *MPVPlayer) IsAvailable() bool

IsAvailable checks if mpv is available on the system.

func (*MPVPlayer) Play added in v0.2.2

func (p *MPVPlayer) Play(ctx context.Context, url string) error

Play plays a single media URL.

func (*MPVPlayer) PlayMultiple added in v0.2.2

func (p *MPVPlayer) PlayMultiple(ctx context.Context, urls []string) error

PlayMultiple plays multiple URLs as a playlist. Users can navigate between items using 'n' (next) in mpv.

type PlayOutcome added in v0.3.24

type PlayOutcome struct {
	ExitCode  int    // 0 on clean exit; -1 when killed by a signal
	Signal    string // signal name when killed by a signal, "" otherwise
	ErrorLine string // most relevant stderr line, token-redacted
}

PlayOutcome describes how an mpv run ended, error or not, so callers can spot streams that "played" without ever starting (e.g. an instant EOF that exits 0).

func PlayMultipleWithOptions added in v0.2.2

func PlayMultipleWithOptions(streamURLs []string, mpvPath string, opts PlaybackOptions) (*PlayOutcome, error)

PlayMultipleWithOptions launches MPV with custom options and reports how the run ended. The outcome is non-nil whenever mpv actually ran, error or not.

type PlaybackError added in v0.3.24

type PlaybackError struct {
	ExitCode int    // mpv's exit code; -1 when killed by a signal
	Signal   string // signal name when killed by a signal, "" otherwise
	Detail   string // most relevant stderr line, "" if mpv wrote nothing useful
}

PlaybackError reports that mpv exited with one of its documented failure codes (1 = fatal error, 2 = file could not be played, 3 = some files failed) or was killed by a signal. A clean exit — including the user quitting — is not a PlaybackError.

func (*PlaybackError) Error added in v0.3.24

func (e *PlaybackError) Error() string

type PlaybackOptions added in v0.2.2

type PlaybackOptions struct {
	SocketPath string // IPC socket path for progress tracking (Unix socket or Windows named pipe, empty to disable)
	StartPos   int    // Start position in seconds (0 to start from beginning)
}

PlaybackOptions configures MPV playback behavior.

Jump to

Keyboard shortcuts

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