I've been doing something similar, in the sense that I want to control VLC from python via DBus.
What I did was to setup VLC as a DBus activatable service. To do that I needed to do two things:
- Define the DBus service
- Define the systemd unit file for VLC, which will be activated when dbus detects activity in #1.
For the DBus service, I needed to create a file in /usr/share/dbus-1/services
. I called it org.mpris.MediaPlayer2.vlc.service
. I couldn't find the way to set it up in a user directory, unfortunately.
# /usr/share/dbus-1/services/org.mpris.MediaPlayer2.vlc.service
[D-BUS Service]
Name=org.mpris.MediaPlayer2.vlc
Exec=/bin/false
SystemdService=vlc.service
With this information, we tell DBus that any activity regarding the bus defined by Name
(org.mpris.MediaPlayer2.vlc
) will need to activate the service vlc.service
. Therefore, we need to define such service via a systemd unit file. You can place this file in either ~/.config/sytemd/user/
(for a user service) or in /usr/lib/systemd/user/
(for a system service).
# vlc.service
[Unit]
Description=VLC media player DBus activated service
[Service]
Type=dbus
BusName=org.mpris.MediaPlayer2.vlc
Environment=""
ExecStart=/home/jbellon/test/ytube-dl/vlc/install/usr/bin/vlc -I "dummy"
Note that the service type here is DBus. You can check out the properties of DBus services in the Systemd unit file documentation.
It has been a while since I got it right (and I didn't dare to change it since), but I think I had problems using cvlc
, so I went straight with the main program using the dummy interface (-I "dummy"
), which is basically the same thing.
Once I got this sorted out, you just need to make sure Systemd knows about the VLC service (systemctl daemon-reload
) and so does DBus (you need to restart DBus for this).
To test it out, you could try to query anything to the DBus service, such as introspecting the interface:
$ systemctl --user status vlc --lines 0
● vlc.service - VLC media player DBus activated service
Loaded: loaded (vlc.service; bad; vendor preset: enabled)
Active: inactive (dead)
$ gdbus introspect --session --dest org.mpris.MediaPlayer2.vlc -o /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2 &> /dev/null
$ systemctl --user status vlc --lines 0
● vlc.service - VLC media player DBus activated service
Loaded: loaded (vlc.service; bad; vendor preset: enabled)
Active: active (running) since Mon 2020-08-17 22:43:53 BST; 1s ago
Main PID: 56522 (vlc)
Tasks: 4 (limit: 38349)
Memory: 2.0M
CPU: 13ms
CGroup: /user.slice/user-1000.slice/user@1000.service/vlc.service
└─56522 /usr/bin/vlc -I dummy