Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for D-Bus control #1279

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
- [Running as a Service](./config/services/README.md)
- [Running as systemd service](./config/services/Systemd.md)
- [Running as launchd service (MacOS)](./config/services/MacOS.md)
- Other
- [D-Bus control](./other/D-Bus-control.md)

57 changes: 57 additions & 0 deletions docs/src/other/D-Bus-control.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# D-Bus control

`Spotifyd` can be configured to bind to D-Bus, exposing controls including standard MPRIS interfaces.

To configure D-Bus, see `use_mpris` and `dbus_type` in the [configuration file](../config/File.md). `Spotifyd` must also be built with the `dbus_mpris` feature, which is available in the `full` flavour of the [provided binaries](https://github.com/Spotifyd/spotifyd/releases).

The D-Bus service name will be in the format `org.mpris.MediaPlayer2.spotifyd.instance<number>`, where `<number>` is the process id.

## Interfaces

### MPRIS

The `org.mpris.MediaPlayer2` and `org.mpris.MediaPlayer2.Player` interfaces from the [MPRIS specification](https://specifications.freedesktop.org/mpris-spec/latest/) are implemented.

Note the `Volume` property of the `org.mpris.MediaPlayer2.Player` interface is read-only, despite supporting writes in the specification.

### Spotifyd Controls

The `rs.spotifyd.Controls` interface includes additional non-standard controls.

- Method `TransferPlayback`: transfers Spotify playback to `spotifyd`
- Method `VolumeUp`: increases player volume
- Method `VolumeDown`: decreases player volume

## Usage

`Spotifyd` can be controlled by applications which support MPRIS such as the [playerctl](https://github.com/altdesktop/playerctl) command-line utility.

The `dbus-send` command can also be used to control `spotifyd`. For example:

- Find the service registered by `spotifyd`: `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep spotifyd`
- Transfer playback to `spotifyd`: `dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotifyd.instancexxx /rs/spotifyd/Controls rs.spotifyd.Controls.TransferPlayback`
- Get metadata for the current track: `dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotifyd.instancexxx /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata`

## Troubleshooting

### "Failed to initialize DBus connection" on a headless system

Where no graphical session is available, the system bus can be used by setting the `dbus_type` configuration option to `system`.

### "Failed to register dbus player name" using the system bus

`Spotifyd` may not have permission to register the D-Bus service due to D-Bus security policies. It should be granted permission to own any service with the prefix "org.mpris.MediaPlayer2.spotifyd".

For example, this statement can be added to the default policy in `/usr/share/dbus-1/system.conf`.

```xml
<allow own_prefix="org.mpris.MediaPlayer2.spotifyd"/>
```

It may also be necessary to add a statement to allow clients to send messages.

```xml
<allow send_destination_prefix="org.mpris.MediaPlayer2.spotifyd"/>
```

Make sure to reload the D-Bus configuration after making changes. For example `sudo systemctl reload dbus`.