1

OK, this is weird. I have been battling this all day & have been unsuccessful as of yet. I am working on a project that is Python based. The project is started via systemd scripts. Weird thing is vlc/cvlc works to an extent, but there is no dbus control. If I run the python app from the command line, everything works perfectly. Running the app from systemd is the wonkiness.

For instance, when it is run with the following code & service script, I can't control vlc with dbus. If I run the python outside of systemd script, I can access the dbus. There is another weird issue that is a side effect of whatever is causing this problem. It will run 1080 vid just fine but not 4k. Try it out with the following & let me know if you can figure it out. I greatly appreciate any & all help. Thanks!

PYTHON CODE (testvlc):

#!/usr/bin/env python

from subprocess import Popen, PIPE
import time

vid = 'somevideo.mp4'
cmd = 'DISPLAY=:0 cvlc -f --no-osd %s -L' % vid
Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
while True:
    print("Hello!")
    time.sleep(5)

SYSTEMD SCRIPT (testvlc.service):

[Unit]
Description=Test VLC From Python Script

[Service]
User=user
ExecStart=/usr/bin/screen -D -S testvlc -m /home/user/testvlc

[Install]
WantedBy=multi-user.target
2
  • If you've found a solution, you should write it up as an answer, not modify the question. I have rolled back your edit. – Kusalananda Jun 25 '20 at 16:48
  • Thanks @Kusalananda, I have "undeleted" my previous answer, wasn't sure exactly how to go about it. – Rich Johnson Jun 25 '20 at 18:36
0
[Unit]
Description=Test VLC From Python Script

[Service]
User=user
Environment="DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1001/bus"
ExecStart=/usr/bin/screen -D -S testvlc -m /home/user/testvlc

[Install]
WantedBy=multi-user.target

Also, if you run this from ~/.config/systemd/user it will run everything just fine including 4K. Changed the wantedby to default.target & add a After=graphical-session.target, remover the User= & the Environment=, & use systemctl --user

0

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:

  1. Define the DBus service
  2. 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.