mpris

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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).

View Source
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

View Source
var ErrNoPlayer = errors.New("mpris: no such player")

ErrNoPlayer reports a control aimed at a bus name the service does not track.

Functions

func Ignored

func Ignored(busName string, patterns []string) bool

Ignored is monitoring.rs should_ignore: a plain substring match of any pattern against the bus name.

func ServeDaemon

func ServeDaemon(conn *dbus.Conn, s *Service) (func(), error)

ServeDaemon exports the interface over the media service.

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

func (d *Daemon) GetActivePlayer() (string, *dbus.Error)

GetActivePlayer names the active player, "" when none.

func (*Daemon) GetPlayerInfo

func (d *Daemon) GetPlayerInfo(player string) (map[string]string, *dbus.Error)

GetPlayerInfo is the player's snapshot as a string map (Player::get with the Rust enums' Debug spellings).

func (*Daemon) ListPlayers

func (d *Daemon) ListPlayers() ([]PlayerRow, *dbus.Error)

ListPlayers lists the players.

func (*Daemon) Next

func (d *Daemon) Next(player string) *dbus.Error

Next skips forward.

func (*Daemon) PlayPause

func (d *Daemon) PlayPause(player string) *dbus.Error

PlayPause toggles playback.

func (*Daemon) Previous

func (d *Daemon) Previous(player string) *dbus.Error

Previous skips back.

func (*Daemon) Seek

func (d *Daemon) Seek(player string, positionUS int64) *dbus.Error

Seek moves to positionUS within the track; negative clamps to 0.

func (*Daemon) SetActivePlayer

func (d *Daemon) SetActivePlayer(player string) *dbus.Error

SetActivePlayer picks the active player; "" clears it.

func (*Daemon) SetLoopStatus

func (d *Daemon) SetLoopStatus(player, mode string) *dbus.Error

SetLoopStatus takes none, track, or playlist (any case).

func (*Daemon) SetShuffle

func (d *Daemon) SetShuffle(player, state string) *dbus.Error

SetShuffle takes on, off, or toggle (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).

const (
	LoopNone LoopMode = iota
	LoopTrack
	LoopPlaylist
	LoopUnsupported
)

Loop modes.

func ParseLoopMode

func ParseLoopMode(status string) LoopMode

ParseLoopMode maps MPRIS's LoopStatus.

func (LoopMode) Next

func (m LoopMode) Next() (LoopMode, bool)

Next is toggle_loop's cycle: None, Track, Playlist, None; false for an unsupported mode.

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

func SelectBest(players []Player, priority []string) (Player, bool)

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 PlayerRow

type PlayerRow struct {
	ID       string
	Identity string
	State    string
}

PlayerRow is one ListPlayers row: (id, identity, playback state).

type Service

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

Service is the live Source on a bus.

func New

func New(conn *dbus.Conn, ignored, priority []string) (*Service, error)

New starts the service on conn: 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 NewSession

func NewSession(ignored, priority []string) (*Service, error)

NewSession connects to the session bus and starts the service.

func (*Service) Active

func (s *Service) Active() (Player, bool)

Active implements Source.

func (*Service) Close

func (s *Service) Close() error

Close stops following the bus and drops the connection.

func (*Service) Next

func (s *Service) Next(ctx context.Context, busName string) error

Next implements Source.

func (*Service) PlayPause

func (s *Service) PlayPause(ctx context.Context, busName string) error

PlayPause implements Source.

func (*Service) Players

func (s *Service) Players() []Player

Players implements Source.

func (*Service) Position

func (s *Service) Position(ctx context.Context, busName string) (time.Duration, error)

Position implements Source.

func (*Service) Previous

func (s *Service) Previous(ctx context.Context, busName string) error

Previous implements Source.

func (*Service) SetActive

func (s *Service) SetActive(busName string) error

SetActive implements Source (service.rs set_active_player). An empty bus name clears the active player.

func (*Service) SetLoop

func (s *Service) SetLoop(ctx context.Context, busName string, mode LoopMode) error

SetLoop sets the LoopStatus property (player set_loop_mode); LoopUnsupported is refused.

func (*Service) SetPosition

func (s *Service) SetPosition(ctx context.Context, busName string, pos time.Duration) error

SetPosition implements Source: SetPosition on the current track id, the NoTrack path when the player publishes none.

func (*Service) SetShuffle

func (s *Service) SetShuffle(ctx context.Context, busName string, on bool) error

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

func (s *Service) ToggleLoop(ctx context.Context, busName string) error

ToggleLoop implements Source: the None, Track, Playlist cycle.

func (*Service) ToggleShuffle

func (s *Service) ToggleShuffle(ctx context.Context, busName string) error

ToggleShuffle implements Source.

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.

Jump to

Keyboard shortcuts

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