Documentation
¶
Overview ¶
Package mpris is the media player service over MPRIS2 (D-Bus), the Go counterpart of crates/wayle-media: it discovers players by bus name, keeps each one's snapshot current from PropertiesChanged, picks the active player the way selection.rs does, and drives the transport (play/pause, next, previous, seek, loop, shuffle).
Index ¶
- Constants
- Variables
- func Ignored(busName string, patterns []string) bool
- func ServeDaemon(conn *dbus.Conn, s *Service) (func(), error)
- type Daemon
- func (d *Daemon) GetActivePlayer() (string, *dbus.Error)
- func (d *Daemon) GetPlayerInfo(player string) (map[string]string, *dbus.Error)
- func (d *Daemon) ListPlayers() ([]PlayerRow, *dbus.Error)
- func (d *Daemon) Next(player string) *dbus.Error
- func (d *Daemon) PlayPause(player string) *dbus.Error
- func (d *Daemon) Previous(player string) *dbus.Error
- func (d *Daemon) Seek(player string, positionUS int64) *dbus.Error
- func (d *Daemon) SetActivePlayer(player string) *dbus.Error
- func (d *Daemon) SetLoopStatus(player, mode string) *dbus.Error
- func (d *Daemon) SetShuffle(player, state string) *dbus.Error
- type LoopMode
- type PlaybackState
- type Player
- type PlayerRow
- type Service
- func (s *Service) Active() (Player, bool)
- func (s *Service) Close() error
- func (s *Service) Next(ctx context.Context, busName string) error
- func (s *Service) PlayPause(ctx context.Context, busName string) error
- func (s *Service) Players() []Player
- func (s *Service) Position(ctx context.Context, busName string) (time.Duration, error)
- func (s *Service) Previous(ctx context.Context, busName string) error
- func (s *Service) SetActive(busName string) error
- func (s *Service) SetLoop(ctx context.Context, busName string, mode LoopMode) error
- func (s *Service) SetPosition(ctx context.Context, busName string, pos time.Duration) error
- func (s *Service) SetShuffle(ctx context.Context, busName string, on bool) error
- func (s *Service) Subscribe() (<-chan struct{}, func())
- func (s *Service) ToggleLoop(ctx context.Context, busName string) error
- func (s *Service) ToggleShuffle(ctx context.Context, busName string) error
- func (s *Service) TrackChanges() (<-chan TrackChange, func())
- type Source
- type TrackChange
Constants ¶
const ( DaemonName = "dev.stubbe.lys.Media1" DaemonPath = dbus.ObjectPath("/dev/stubbe/lys/Media") )
lys-shell's own interface over the media service, which `lys-shell media` drives (wayle-media/src/dbus).
const ( BusNamePrefix = "org.mpris.MediaPlayer2." ObjectPath = dbus.ObjectPath("/org/mpris/MediaPlayer2") RootIface = "org.mpris.MediaPlayer2" PlayerIface = "org.mpris.MediaPlayer2.Player" )
D-Bus names of the MPRIS2 surface.
Variables ¶
var ErrNoPlayer = errors.New("mpris: no such player")
ErrNoPlayer reports a control aimed at a bus name the service does not track.
Functions ¶
Types ¶
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon is the dev.stubbe.lys.Media1 object (dbus/server.rs MediaDaemon) over the shell's media service.
func (*Daemon) GetActivePlayer ¶
GetActivePlayer names the active player, "" when none.
func (*Daemon) GetPlayerInfo ¶
GetPlayerInfo is the player's snapshot as a string map (Player::get with the Rust enums' Debug spellings).
func (*Daemon) ListPlayers ¶
ListPlayers lists the players.
func (*Daemon) SetActivePlayer ¶
SetActivePlayer picks the active player; "" clears it.
func (*Daemon) SetLoopStatus ¶
SetLoopStatus takes none, track, or playlist (any case).
type LoopMode ¶
type LoopMode uint8
LoopMode is the player's LoopStatus; LoopUnsupported marks a player without the property or with an unknown value (types.rs LoopMode).
func ParseLoopMode ¶
ParseLoopMode maps MPRIS's LoopStatus.
type PlaybackState ¶
type PlaybackState uint8
PlaybackState is the player's transport state.
const ( StateStopped PlaybackState = iota StatePlaying StatePaused )
Playback states.
func StateFromString ¶
func StateFromString(status string) PlaybackState
StateFromString maps MPRIS's PlaybackStatus.
type Player ¶
type Player struct {
// BusName is the full well-known name (org.mpris.MediaPlayer2.x).
BusName string
Identity string
DesktopEntry string
Title string
Artist string
Album string
ArtURL string
TrackID string
// Length is the track length; zero when the player reports none.
Length time.Duration
State PlaybackState
Loop LoopMode
Shuffle bool
CanGoNext bool
CanGoPrevious bool
CanSeek bool
// CanLoop and CanShuffle report whether the player publishes the
// LoopStatus and Shuffle properties at all (player/mod.rs probes
// the reads the same way).
CanLoop bool
CanShuffle bool
// Volume is the player's Volume property, 0..1 (0 when unpublished).
Volume float64
}
Player is one player's snapshot.
func SelectBest ¶
SelectBest is selection.rs select_best_player: the first priority pattern (in order) that matches a player's bus name, else the first playing player, else the first player. Patterns are wayle-media's case-sensitive wildcards.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the live Source on a bus.
func New ¶
New starts the service on conn, which stays the caller's: it matches the player and bus-owner signals, discovers the players already on the bus, and follows them. ignored and priority are the players-ignored and player-priority config lists.
func (*Service) SetActive ¶
SetActive implements Source (service.rs set_active_player). An empty bus name clears the active player.
func (*Service) SetLoop ¶
SetLoop sets the LoopStatus property (player set_loop_mode); LoopUnsupported is refused.
func (*Service) SetPosition ¶
SetPosition implements Source: SetPosition on the current track id, the NoTrack path when the player publishes none.
func (*Service) SetShuffle ¶
SetShuffle sets the Shuffle property (player set_shuffle_mode).
func (*Service) Subscribe ¶
func (s *Service) Subscribe() (<-chan struct{}, func())
Subscribe implements Source.
func (*Service) ToggleLoop ¶
ToggleLoop implements Source: the None, Track, Playlist cycle.
func (*Service) ToggleShuffle ¶
ToggleShuffle implements Source.
func (*Service) TrackChanges ¶ added in v0.3.15
func (s *Service) TrackChanges() (<-chan TrackChange, func())
TrackChanges returns a feed of the active player's track changes; stop ends it.
type Source ¶
type Source interface {
// Players lists the tracked players in discovery order.
Players() []Player
// Active returns the active player; false when there is none.
Active() (Player, bool)
// SetActive makes the tracked player with that bus name active (the
// source picker); unknown names are ErrNoPlayer.
SetActive(busName string) error
// Subscribe returns a feed that ticks on every player-set, active,
// or snapshot change; stop ends it.
Subscribe() (<-chan struct{}, func())
// PlayPause, Next, and Previous drive the transport.
PlayPause(ctx context.Context, busName string) error
Next(ctx context.Context, busName string) error
Previous(ctx context.Context, busName string) error
// SetPosition seeks the current track to pos.
SetPosition(ctx context.Context, busName string, pos time.Duration) error
// ToggleLoop and ToggleShuffle step the loop cycle and flip shuffle.
ToggleLoop(ctx context.Context, busName string) error
ToggleShuffle(ctx context.Context, busName string) error
// Position reads the live playback position (MPRIS emits no change
// signal for it, so the dropdown polls).
Position(ctx context.Context, busName string) (time.Duration, error)
}
Source is what the media module and dropdown read and drive.
type TrackChange ¶ added in v0.3.15
TrackChange is the active player moving to another track. Requested marks a change the user asked for through the daemon's Next or Previous (a media key, `lys-shell media next`), not the player advancing on its own.