playerctl

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: LGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPlayerNotFound indicates that no player matching the selector could be found.
	ErrPlayerNotFound = errors.New("player not found")
)

Functions

func ExtractAlbum added in v0.0.3

func ExtractAlbum(meta map[string]dbus.Variant) string

ExtractAlbum returns the xesam:album string from a metadata map.

func ExtractArtist added in v0.0.3

func ExtractArtist(meta map[string]dbus.Variant) string

ExtractArtist returns a best-effort artist string from a metadata map.

func ExtractTitle added in v0.0.3

func ExtractTitle(meta map[string]dbus.Variant) string

ExtractTitle returns the xesam:title string from a metadata map.

func ExtractTrackID added in v0.0.3

func ExtractTrackID(meta map[string]dbus.Variant) string

ExtractTrackID returns the mpris:trackid string from a metadata map.

func StringInstanceCompare

func StringInstanceCompare(name, instance string) int

StringInstanceCompare compares a player instance string with a matcher string. Supports "%any" matcher and partial instance matching (e.g., "vlc" matches "vlc.instanceXXXX").

Types

type FormatError

type FormatError struct {
	Message string
}

FormatError reports a formatter parse or rendering error.

func (FormatError) Error

func (e FormatError) Error() string

Error implements the error interface.

type Formatter

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

Formatter expands text/template expressions using a string context.

func NewFormatter

func NewFormatter(format string) (*Formatter, error)

NewFormatter constructs a formatter for a template string.

func (*Formatter) ContainsKey

func (f *Formatter) ContainsKey(key string) bool

ContainsKey reports whether the template references the provided key.

func (*Formatter) Expand

func (f *Formatter) Expand(context map[string]string) (string, error)

Expand substitutes template variables using values from context.

type InvalidCommandError

type InvalidCommandError struct {
	Command string
}

InvalidCommandError indicates that a command is not supported by the current player or context.

func (InvalidCommandError) Error

func (e InvalidCommandError) Error() string

Error implements the error interface.

type LoopStatus

type LoopStatus int

LoopStatus represents the loop status for a PlayerctlPlayer.

const (
	// LoopStatusNone means playback stops when no tracks remain.
	LoopStatusNone LoopStatus = iota
	// LoopStatusTrack means the current track repeats.
	LoopStatusTrack
	// LoopStatusPlaylist means the active playlist repeats.
	LoopStatusPlaylist
)

func ParseLoopStatus

func ParseLoopStatus(statusStr string) (LoopStatus, bool)

ParseLoopStatus parses a string into a LoopStatus. Returns the parsed status and a boolean indicating success.

func (LoopStatus) String

func (s LoopStatus) String() string

String returns the string representation of the LoopStatus.

type PlaybackStatus

type PlaybackStatus int

PlaybackStatus represents the playback status for a Player.

const (
	// PlaybackStatusPlaying indicates active playback.
	PlaybackStatusPlaying PlaybackStatus = iota
	// PlaybackStatusPaused indicates playback is paused.
	PlaybackStatusPaused
	// PlaybackStatusStopped indicates playback has stopped.
	PlaybackStatusStopped
)

func ParsePlaybackStatus

func ParsePlaybackStatus(statusStr string) (PlaybackStatus, bool)

ParsePlaybackStatus parses a string into a PlaybackStatus. Returns the parsed status and a boolean indicating success.

func (PlaybackStatus) String

func (s PlaybackStatus) String() string

String returns the string representation of the PlaybackStatus.

type Player

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

Player models a single controllable media player connection.

func NewPlayer

func NewPlayer(instance string, source Source) (*Player, error)

NewPlayer creates a Player from an instance string and source.

func NewPlayerFromName

func NewPlayerFromName(name *PlayerName) (*Player, error)

NewPlayerFromName creates a Player from a fully qualified PlayerName.

func (*Player) CanControl

func (p *Player) CanControl() (bool, error)

CanControl reports whether the player supports control actions.

func (*Player) CanGoNext

func (p *Player) CanGoNext() (bool, error)

func (*Player) CanGoPrevious

func (p *Player) CanGoPrevious() (bool, error)

func (*Player) CanPause

func (p *Player) CanPause() (bool, error)

func (*Player) CanPlay

func (p *Player) CanPlay() (bool, error)

func (*Player) CanSeek

func (p *Player) CanSeek() (bool, error)

func (*Player) Close

func (p *Player) Close()

Close marks the Player as closed and releases locally held state.

func (*Player) Closed

func (p *Player) Closed() bool

Closed reports whether the player has been closed.

func (*Player) Disappeared

func (p *Player) Disappeared() bool

Disappeared reports whether the player service vanished from D-Bus.

func (*Player) GetAlbum

func (p *Player) GetAlbum() (string, error)

GetAlbum returns xesam:album metadata.

func (*Player) GetArtist

func (p *Player) GetArtist() (string, error)

GetArtist returns a best-effort artist string from metadata.

func (*Player) GetTitle

func (p *Player) GetTitle() (string, error)

GetTitle returns xesam:title metadata.

func (*Player) GetTrackID

func (p *Player) GetTrackID() (string, error)

GetTrackID returns mpris:trackid metadata.

func (*Player) Instance

func (p *Player) Instance() string

Instance returns the full player instance.

func (*Player) LoopStatus

func (p *Player) LoopStatus() (LoopStatus, error)

LoopStatus returns the player's loop status.

func (*Player) Metadata

func (p *Player) Metadata() (map[string]dbus.Variant, error)

Metadata returns metadata map values.

func (*Player) Name

func (p *Player) Name() string

Name returns the short player name.

func (*Player) Next

func (p *Player) Next() error

func (*Player) OpenURI

func (p *Player) OpenURI(uri string) error

OpenURI is a compatibility alias for OpenUri.

func (*Player) OpenUri

func (p *Player) OpenUri(uri string) error

func (*Player) Pause

func (p *Player) Pause() error

func (*Player) Play

func (p *Player) Play() error

Play starts playback.

func (*Player) PlayPause

func (p *Player) PlayPause() error

func (*Player) PlaybackStatus

func (p *Player) PlaybackStatus() (PlaybackStatus, error)

PlaybackStatus returns the player's current playback status.

func (*Player) Position

func (p *Player) Position() (int64, error)

Position returns current track position in microseconds.

func (*Player) Previous

func (p *Player) Previous() error

func (*Player) Seek

func (p *Player) Seek(offset int64) error

func (*Player) SetLoopStatus

func (p *Player) SetLoopStatus(status LoopStatus) error

SetLoopStatus sets loop mode.

func (*Player) SetPosition

func (p *Player) SetPosition(trackID string, position int64) error

func (*Player) SetShuffle

func (p *Player) SetShuffle(enabled bool) error

SetShuffle toggles shuffle mode.

func (*Player) SetVolume

func (p *Player) SetVolume(volume float64) error

SetVolume sets the player volume.

func (*Player) Shuffle

func (p *Player) Shuffle() (bool, error)

Shuffle returns whether shuffle is enabled.

func (*Player) Source

func (p *Player) Source() Source

Source returns the bus source used by this player.

func (*Player) Stop

func (p *Player) Stop() error

func (*Player) Volume

func (p *Player) Volume() (float64, error)

Volume returns player volume.

func (*Player) WaitForDisappear

func (p *Player) WaitForDisappear(timeout time.Duration) bool

WaitForDisappear waits for the player to vanish or timeout.

type PlayerManager

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

PlayerManager tracks discovered players and managed player instances.

func NewPlayerManager

func NewPlayerManager(source Source) (*PlayerManager, error)

NewPlayerManager constructs a manager for a given bus source.

func (*PlayerManager) FilterPlayerNames

func (m *PlayerManager) FilterPlayerNames(allow []string, ignore []string) []*PlayerName

FilterPlayerNames applies --player/%any style selection and ignore lists.

func (*PlayerManager) HandleNameOwnerChanged

func (m *PlayerManager) HandleNameOwnerChanged(busName, oldOwner, newOwner string, source Source)

HandleNameOwnerChanged updates manager state based on NameOwnerChanged signal args.

func (*PlayerManager) ManagePlayer

func (m *PlayerManager) ManagePlayer(player *Player)

ManagePlayer adds a connected player to the managed list.

func (*PlayerManager) MovePlayerToTop

func (m *PlayerManager) MovePlayerToTop(player *Player)

MovePlayerToTop moves a managed player to the front, preserving order otherwise.

func (*PlayerManager) PlayerNames

func (m *PlayerManager) PlayerNames() []*PlayerName

PlayerNames returns a copy of discovered player names.

func (*PlayerManager) Players

func (m *PlayerManager) Players() []*Player

Players returns a copy of managed players.

func (*PlayerManager) Refresh

func (m *PlayerManager) Refresh() error

Refresh performs discovery via org.freedesktop.DBus ListNames.

func (*PlayerManager) SortPlayersByActivity

func (m *PlayerManager) SortPlayersByActivity(weight func(*Player) int)

SortPlayersByActivity applies stable ordering callback. Lower weight ranks first.

func (*PlayerManager) Source

func (m *PlayerManager) Source() Source

Source returns manager bus source.

type PlayerName

type PlayerName struct {
	Name     string
	Instance string
	Source   Source
}

PlayerName contains connection information that fully qualifies a potential connection to a player.

func NewPlayerName

func NewPlayerName(instance string, source Source) *PlayerName

NewPlayerName creates a new PlayerName instance. instance is the complete name and instance of the player.

func (*PlayerName) Compare

func (p *PlayerName) Compare(other *PlayerName) int

Compare compares two PlayerNames. It returns 0 if they are equal, otherwise non-zero.

func (*PlayerName) InstanceCompare

func (p *PlayerName) InstanceCompare(other *PlayerName) int

InstanceCompare compares a PlayerName to another PlayerName treating the second as an instance matcher. Returns 0 if they match, otherwise non-zero.

type Source

type Source int

Source represents the source of the name used to control the player.

const (
	// SourceNone is used for uninitialized players; source is chosen automatically.
	SourceNone Source = iota
	// SourceDBusSession selects the D-Bus session bus.
	SourceDBusSession
	// SourceDBusSystem selects the D-Bus system bus.
	SourceDBusSystem
)

func (Source) String

func (s Source) String() string

String returns the string representation of the Source.

Jump to

Keyboard shortcuts

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