Documentation
¶
Overview ¶
Package player provides an mpv IPC wrapper for audio playback control.
Index ¶
- func LaunchCmd(p Player, url string, startTime float64, paused bool, httpHeaders []string) tea.Cmd
- func MpvSocketDir() string
- func QuitCmd(p Player) tea.Cmd
- func SetSpeedCmd(p Player, speed float64) tea.Cmd
- func SetVolumeCmd(p Player, vol int) tea.Cmd
- func TickCmd(p Player, generation uint64) tea.Cmd
- func TogglePauseCmd(p Player, shouldPlay bool) tea.Cmd
- type IPCConnection
- type Model
- type Mpv
- func (m *Mpv) Connect() error
- func (m *Mpv) GetDuration() (float64, error)
- func (m *Mpv) GetPaused() (bool, error)
- func (m *Mpv) GetPosition() (float64, error)
- func (m *Mpv) GetVolume() (int, error)
- func (m *Mpv) Launch(url, startTime, socketPath string, paused bool, httpHeaders []string) error
- func (m *Mpv) Quit() error
- func (m *Mpv) Seek(seconds float64) error
- func (m *Mpv) SetPause(paused bool) error
- func (m *Mpv) SetSpeed(speed float64) error
- func (m *Mpv) SetVolume(vol int) error
- type Player
- type PlayerKeyMap
- type PlayerLaunchErrMsg
- type PlayerQuitMsg
- type PlayerReadyMsg
- type PositionMsg
- type ProcessStarter
- type StartPlayMsg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LaunchCmd ¶
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 SetSpeedCmd ¶
SetSpeedCmd sends a speed change to mpv.
func SetVolumeCmd ¶
SetVolumeCmd sends a volume change 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 (Model) HandlesKey ¶
HandlesKey reports whether the player should consume the key while a session is active.
func (Model) SeekBackKey ¶
SeekBackKey returns the seek backward key binding.
func (Model) SeekForwardKey ¶
SeekForwardKey returns the seek forward key binding.
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) GetDuration ¶
GetDuration returns the total duration in seconds.
func (*Mpv) GetPosition ¶
GetPosition returns the current playback position in seconds.
func (*Mpv) Launch ¶
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.
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 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 ¶
ProcessStarter abstracts process spawning for testability.
type StartPlayMsg ¶
type StartPlayMsg struct {
Title string
}
StartPlayMsg signals that playback should begin.