dependency: gvfs for cover art caching NixOS: services.gvfs
Not every media player supports position, volume and other functionality.
Support varies from player to player.
changed: emits on any state change except position changeplayer-changed: (busName: string)player-closed: (busName: string)player-added: (busName: string)players: Player[] see belowcacheCoverArt: boolean wether to cache track-cover-url, default: truegetPlayer: (string) => Player returns Player that has given string in its
busNameposition: (position: number) this is signaled when the position is set
explicitlyclosedbus-name: string the dbus name that starts with org.mpris.MediaPlayer2name: string stripped from busName like spotify or firefoxidentity: string name of the player like Spotify or Mozilla Firefoxentry: string .desktop entry without the extensiontrackid: stringtrack-artists: string[] list of artiststrack-title: stringtrack-album: stringtrack-cover-url: string url to the cover artcover-path: string path to the cached cover artmetadata: { [key: string]: unknown } metadata object, see
freedesktop.org
for known keysplay-back-status: "Playing" | "Paused" | "Stopped"can-go-next: booleancan-go-prev: booleancan-play: booleanshuffle-status: boolean | null null if unsupported by the playerloop-status: "None" | "Track" | "Playlist" | null null if unsupported by
the playervolume: number -1 if unsupported by the playerlength: number -1 if unsupported by the playerposition: number -1 if unsupported by the playerplayPause: () => voidplay: () => voidstop: () => voidnext: () => voidprevious: () => voidshuffle: () => voidloop: () => voidconst mpris = await Service.import("mpris");
/** @param {import('types/service/mpris').MprisPlayer} player */
const Player = (player) =>
Widget.Button({
onClicked: () => player.playPause(),
child: Widget.Label().hook(player, (label) => {
const { track_artists, track_title } = player;
label.label = `${track_artists.join(", ")} - ${track_title}`;
}),
});
const players = Widget.Box({
children: mpris.bind("players").as((p) => p.map(Player)),
});
(Image: media-widget)