player

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package player provides an mpv IPC wrapper for audio playback control.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LaunchCmd

func LaunchCmd(p Player, url string, startTime float64, paused bool, httpHeaders []string) tea.Cmd

LaunchCmd spawns mpv and connects via IPC. If paused is true, mpv starts paused. httpHeaders are passed to mpv via --http-header-fields. Returns PlayerReadyMsg on success.

func MpvSocketDir

func MpvSocketDir() string

MpvSocketDir returns the directory where mpv can create IPC sockets. For snap-packaged mpv, this is ~/snap/mpv/common/ since snap's /tmp is isolated. For native mpv, this is os.TempDir().

func QuitCmd

func QuitCmd(p Player) tea.Cmd

QuitCmd stops mpv playback.

func SetSpeedCmd

func SetSpeedCmd(p Player, speed float64) tea.Cmd

SetSpeedCmd sends a speed change to mpv.

func SetVolumeCmd

func SetVolumeCmd(p Player, vol int) tea.Cmd

SetVolumeCmd sends a volume change to mpv.

func TickCmd

func TickCmd(p Player, generation uint64) tea.Cmd

TickCmd returns a command that fires twice per second and polls mpv state. The generation parameter ties the tick to a specific play session so stale ticks from a previous session can be safely ignored.

func TogglePauseCmd

func TogglePauseCmd(p Player, shouldPlay bool) tea.Cmd

TogglePauseCmd sends a pause toggle to mpv.

Types

type IPCConnection

type IPCConnection interface {
	Open() error
	Get(property string) (interface{}, error)
	Set(property string, value interface{}) error
	Call(arguments ...interface{}) (interface{}, error)
	Close() error
	IsClosed() bool
}

IPCConnection abstracts the mpvipc.Connection for testability.

type Model

type Model struct {
	Playing        bool
	Title          string
	Position       float64
	Duration       float64
	Speed          float64
	Volume         int
	SleepRemaining string
	// contains filtered or unexported fields
}

Model is the bubbletea sub-model for the player footer bar.

func NewModel

func NewModel(p Player, cfg config.Config, styles ui.Styles) Model

NewModel creates a new player sub-model.

func (Model) HandlesKey

func (m Model) HandlesKey(msg tea.KeyMsg) bool

HandlesKey reports whether the player should consume the key while a session is active.

func (Model) Init

func (m Model) Init() tea.Cmd

Init returns nil; the player is inactive until playback starts.

func (Model) SeekBackKey

func (m Model) SeekBackKey() key.Binding

SeekBackKey returns the seek backward key binding.

func (Model) SeekForwardKey

func (m Model) SeekForwardKey() key.Binding

SeekForwardKey returns the seek forward key binding.

func (*Model) SetWidth

func (m *Model) SetWidth(w int)

SetWidth sets the available width for rendering.

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update handles messages for the player sub-model.

func (Model) View

func (m Model) View() string

View renders the player footer bar. Returns empty string if inactive.

type Mpv

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

Mpv wraps mpvipc to control an mpv subprocess via IPC.

func NewMpv

func NewMpv() *Mpv

NewMpv creates an Mpv player with default process and connection factories.

func (*Mpv) Connect

func (m *Mpv) Connect() error

Connect opens the IPC connection to mpv.

func (*Mpv) GetDuration

func (m *Mpv) GetDuration() (float64, error)

GetDuration returns the total duration in seconds.

func (*Mpv) GetPaused

func (m *Mpv) GetPaused() (bool, error)

GetPaused returns whether playback is paused.

func (*Mpv) GetPosition

func (m *Mpv) GetPosition() (float64, error)

GetPosition returns the current playback position in seconds.

func (*Mpv) GetVolume

func (m *Mpv) GetVolume() (int, error)

GetVolume returns the current volume level.

func (*Mpv) Launch

func (m *Mpv) Launch(url, startTime, socketPath string, paused bool, httpHeaders []string) error

Launch spawns mpv in audio-only mode with the given IPC socket. If paused is true, mpv starts paused and the user must press play to resume. If a previous mpv process is still running, it is killed first.

func (*Mpv) Quit

func (m *Mpv) Quit() error

Quit sends the quit command and cleans up.

func (*Mpv) Seek

func (m *Mpv) Seek(seconds float64) error

Seek seeks to an absolute position in seconds.

func (*Mpv) SetPause

func (m *Mpv) SetPause(paused bool) error

SetPause pauses or resumes playback.

func (*Mpv) SetSpeed

func (m *Mpv) SetSpeed(speed float64) error

SetSpeed sets the playback speed multiplier.

func (*Mpv) SetVolume

func (m *Mpv) SetVolume(vol int) error

SetVolume sets the playback volume (0-150).

type Player

type Player interface {
	Launch(url, startTime, socketPath string, paused bool, httpHeaders []string) error
	Connect() error
	GetPosition() (float64, error)
	GetDuration() (float64, error)
	GetPaused() (bool, error)
	SetPause(paused bool) error
	Seek(seconds float64) error
	SetSpeed(speed float64) error
	SetVolume(vol int) error
	GetVolume() (int, error)
	Quit() error
}

Player defines the interface for media playback control.

type PlayerKeyMap

type PlayerKeyMap struct {
	PlayPause   key.Binding
	SeekForward key.Binding
	SeekBack    key.Binding
	SpeedUp     key.Binding
	SpeedDown   key.Binding
	VolumeUp    key.Binding
	VolumeDown  key.Binding
}

PlayerKeyMap defines keybindings active when the player is playing.

type PlayerLaunchErrMsg

type PlayerLaunchErrMsg struct {
	Err error
}

PlayerLaunchErrMsg signals that mpv failed to launch.

type PlayerQuitMsg

type PlayerQuitMsg struct{}

PlayerQuitMsg signals that mpv has been quit.

type PlayerReadyMsg

type PlayerReadyMsg struct{}

PlayerReadyMsg signals that mpv has been launched and connected.

type PositionMsg

type PositionMsg struct {
	Position   float64
	Duration   float64
	Paused     bool
	Err        error
	Generation uint64 // ties this tick to a specific play session
}

PositionMsg carries the current playback position polled from mpv.

type ProcessStarter

type ProcessStarter func(name string, args ...string) *exec.Cmd

ProcessStarter abstracts process spawning for testability.

type StartPlayMsg

type StartPlayMsg struct {
	Title string
}

StartPlayMsg signals that playback should begin.

Jump to

Keyboard shortcuts

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