Control OMXPlayer from Python on the Raspberry Pi.
Make sure dbus is installed:
$ sudo apt-get install python-dbusFor someone who just wants to use the package:
$ python setup.py installIf you're feeling helpful, and decide to help develop the package:
$ python setup.py developThere's also an Ansible playbook in devenv which will set up a raspberry pi
with omxplayer-wrapper in develop mode (located at
/usr/src/omxplayer-wrapper) which can be used by running ./devenv/deploy.sh
This will install via symlinks so that you can continue to work on it locally but import it from other python packages
from omxplayer import OMXPlayer
from time import sleep
file_path_or_url = 'path/to/file.mp4'
# This will start an `omxplayer` process, this might
# fail the first time you run it, currently in the
# process of fixing this though.
player = OMXPlayer(file_path_or_url)
player.pause()
sleep(5)
player.play()
# Kill the `omxplayer` process gracefully.
player.quit()Playing a stream from a URL (e.g. a live RTMP or RTSP stream) works the same as with a file path, just change the "source" string parameter given to OMXPlayer to a URL instead of a file path.
from omxplayer import OMXPlayer
from time import sleep
file_path_or_url = 'rtmp://192.168.0.1/live/test'
player = OMXPlayer(file_path_or_url)
player.pause()
sleep(5)
player.play()
# Kill the `omxplayer` process gracefully.
player.quit()Playing several instances of omxplayer simultaneously
from omxplayer import OMXPlayer
# Use default dbus name for first instance
player1 = OMXPlayer(file_path_or_url1, pause=True)
# Name of dbus for second instance is just an example
player2 = OMXPlayer(file_path_or_url2, dbus_name='org.mpris.MediaPlayer2.omxplayer1', pause=True)
# Players are initially paused due to the 'pause' argument, but this is not necessary
# That way we can start them synchronously
player1.play()
player2.play()
# Kill the `omxplayer` processes gracefully.
player1.quit()
player2.quit()Choppy streaming over a slow connection? If you're connection isn't good
enough to support streaming, checkout urllib2 to download the file locally
prior to playing.
You can read the docs here: python-omxplayer-wrapper.rtfd.org