2011.03.24: Controlling VLC from PHP via DBus
2011-03-24 01:42 by Ian
I was looking for a way to replace JVLC in the car computer. Mostly, this was motivated by a desire to eliminate the Java component of the software chain. There exists a PHP library that provides a sketchy connection to the DBus, and it appears that there is no official documentation for it. This caused me enough frustration to warrant an explanation regarding what I did to make it work.
Installation was straight-forward. Follow the instructions:
wget http://pecl.php.net/get/dbus-0.1.0.tgz tar xzvf dbus-0.1.0.tgz cd dbus-0.1.0 phpize ./configure make sudo make install
Add the following line to your php.ini file…
extension=dbus.so
Restart apache (if that matters to your situation). Installation complete. My first script looked like this…
<?php $test = new Dbus(); ?>
...and resulted in this error output:
Fatal error: Uncaught exception 'Exception' with message 'Dbus::__construct(): Connection Error (/usr/bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed. ) '
Reading the internets, I came to the conclusion that I needed to specify which DBus I wanted to connect to, and I had no idea how to do that.
After much hair-pulling and reading this URL, I managed to add a listener:
<?php $test = new Dbus(Dbus::BUS_SYSTEM); ?>
...meh. Can’t do anything yet. So let’s install VLC and verify DBus is working by learning how to send a command with it. VLC is easy to setup. Out of the box, the DBus control interface is not enabled. So you have to do that first. Then I was able to start and stop playback with this…
dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Pause
Nifty. Now let’s fix the PHP...
Previous: Metalcraft (PC Case)
Next: Making a simple perfume (orange blossom)