omxplayer API Docs

omxplayer.player

exception omxplayer.player.FileNotFoundError[source]

Bases: Exception

class omxplayer.player.OMXPlayer(source, args=[], bus_address_finder=None, Connection=None, dbus_name=None, pause=False)[source]

Bases: object

OMXPlayer controller

This works by speaking to OMXPlayer over DBus sending messages.

Parameters:

Multiple argument example:

>>> OMXPlayer('path.mp4', args=['--no-osd', '--no-keys', '-b'])
action(code)[source]

Executes a keyboard command via a code

Parameters:code (int) – The key code you wish to emulate refer to keys.py for the possible keys
aspect_ratio()[source]
Returns:aspect ratio
Return type:float
can_control()[source]
Returns:whether the player can be controlled
Return type:bool
can_go_next()[source]
Returns:whether the player can move to the next item in the playlist
Return type:bool
can_go_previous()[source]
Returns:
whether the player can move to the previous item in the
playlist
Return type:bool
can_pause()[source]
Returns:whether the player can pause
Return type:bool
can_play()[source]
Returns:whether the player can play
Return type:bool
can_quit()[source]
Returns:whether the player can quit or not
Return type:bool
can_raise()[source]
Returns:whether the player can raise the display window atop of all other windows
Return type:bool
can_seek()[source]
Returns:whether the player can seek
Return type:bool
can_set_fullscreen()[source]
Returns:whether the player can go fullscreen
Return type:bool
duration()[source]
Returns:duration in seconds
Return type:float
fullscreen()[source]
Returns:whether the player is fullscreen or not
Return type:bool
get_filename()[source]
Returns:source currently playing
Return type:str

Deprecated since version 0.2.0: Use: get_source() instead.

get_source()[source]

Get the source URI of the currently playing media

Returns:source currently playing
Return type:str
has_track_list()[source]
Returns:whether the player has a track list or not
Return type:bool
height()[source]
Returns:video height in px
Return type:int
hide_subtitles()[source]

Hide subtitles

hide_video()[source]

Hides the video overlays

identity()[source]
Returns:Returns omxplayer, the name of the player
Return type:str
is_playing()[source]
Returns:Whether the player is playing
Return type:bool
list_audio()[source]
Returns:
A list of all known audio streams, each item is in the
format: <index>:<language>:<name>:<codec>:<active>
Return type:[str]
list_subtitles()[source]
Returns:
A list of all known subtitles, each item is in the
format: <index>:<language>:<name>:<codec>:<active>
Return type:[str]
list_video()[source]
Returns:
A list of all known video streams, each item is in the
format: <index>:<language>:<name>:<codec>:<active>
Return type:[str]
load(source, pause=False)[source]

Loads a new source (as a file) from source (a file path or URL) by killing the current omxplayer process and forking a new one.

Parameters:source (string) – Path to the file to play or URL
maximum_rate()[source]
Returns:maximum playback rate (as proportion of normal rate)
Return type:float
metadata()[source]
Returns:containing track information (‘URI’, ‘length’)
Return type:dict

Examples

>>> player.metadata()
{
    'mpris:length': 19691000,
    'xesam:url': 'file:///home/name/path/to/media/file.mp4'
}
minimum_rate()[source]
Returns:minimum playback rate (as proportion of normal rate)
Return type:float
mute()[source]

Mute audio. If already muted, then this does not do anything

next()[source]

Skip to the next chapter

Returns:Whether the player skipped to the next chapter
Return type:bool
pause()[source]

Pause playback

pauseEvent = None

Event called on pause callback(player)

play()[source]

Play the video asynchronously returning control immediately to the calling code

playEvent = None

Event called on play callback(player)

play_pause()[source]

Pause playback if currently playing, otherwise start playing if currently paused.

play_sync()[source]

Play the video and block whilst the video is playing

playback_status()[source]
Returns:one of (“Playing” | “Paused” | “Stopped”)
Return type:str
position()[source]
Returns:position in seconds
Return type:int
positionEvent = None

Event called on setting position callback(player, absolute_position)

previous()[source]

Skip to the previous chapter

Returns:Whether the player skipped to the previous chapter
Return type:bool
quit()[source]

Quit the player, blocking until the process has died

rate()[source]
Returns:playback rate, 1 is the normal rate, 0.5 would be half speed and 2 would be double speed.
Return type:float
seek(relative_position)[source]

Seek the video by relative_position seconds

Parameters:relative_position (float) – The position in seconds to seek to.
seekEvent = None

Event called on seek callback(player, relative_position)

select_audio(index)[source]

Select audio stream specified by the index of the stream in list_audio

Parameters:index (int) – index of audio stream returned by list_audio
select_subtitle(index)[source]

Enable a subtitle specified by the index it is listed in list_subtitles

Parameters:index (int) – index of subtitle listing returned by list_subtitles
set_alpha(alpha)[source]

Set the transparency of the video overlay

Parameters:alpha (float) – The transparency (0..255)
set_aspect_mode(mode)[source]

Set the aspect mode of the video

Parameters:mode (str) – One of (“letterbox” | “fill” | “stretch”)
set_position(position)[source]

Set the video to playback position to position seconds from the start of the video

Parameters:position (float) – The position in seconds.
set_rate(rate)[source]

Set the playback rate of the video as a multiple of the default playback speed

Examples

>>> player.set_rate(2)
# Will play twice as fast as normal speed
>>> player.set_rate(0.5)
# Will play half speed
set_video_crop(x1, y1, x2, y2)[source]
Parameters:
  • x1 (int) – Top left x coordinate (px)
  • y1 (int) – Top left y coordinate (px)
  • x2 (int) – Bottom right x coordinate (px)
  • y2 (int) – Bottom right y coordinate (px)
set_video_pos(x1, y1, x2, y2)[source]

Set the video position on the screen

Parameters:
  • x1 (int) – Top left x coordinate (px)
  • y1 (int) – Top left y coordinate (px)
  • x2 (int) – Bottom right x coordinate (px)
  • y2 (int) – Bottom right y coordinate (px)
set_volume(volume)[source]
Parameters:float – volume in millibels
show_subtitles()[source]

Shows subtitles after hide_subtitles

show_video()[source]

Shows the video (to undo a hide_video)

stop()[source]

Stop the player, causing it to quit

stopEvent = None

Event called on stop callback(player)

supported_uri_schemes()[source]
Returns:list of supported URI schemes
Return type:str

Examples

>>> player.supported_uri_schemes()
["file", "http", "rtsp", "rtmp"]
unmute()[source]

Unmutes the video. If already unmuted, then this does not do anything

video_pos()[source]
Returns:
Video spatial position (x1, y1, x2, y2) where (x1, y1) is top left,
and (x2, y2) is bottom right. All values in px.
Return type:(int, int, int, int)
video_stream_count()[source]
Returns:number of video streams
Return type:int
volume()[source]
Returns:current volume in millibels
Return type:float
width()[source]
Returns:video width in px
Return type:int
exception omxplayer.player.OMXPlayerDeadError[source]

Bases: Exception

omxplayer.bus_finder

class omxplayer.bus_finder.BusFinder(path=None)[source]

Bases: object

find_address_file()[source]

Finds the OMXPlayer DBus connection Assumes there is an alive OMXPlayer process. :return:

get_address()[source]
wait_for_dbus_address_to_be_written_to_file()[source]
wait_for_file()[source]
wait_for_path_to_exist()[source]

omxplayer.dbus_connection

class omxplayer.dbus_connection.DBusConnection(bus_address, dbus_name=None)[source]

Bases: object

proxy

The proxy object by which one interacts with a dbus object, this makes communicating with a similar to that of communicating with a POJO.

root_interface

org.mpris.MediaPlayer2 interface proxy object

player_interface

org.mpris.MediaPlayer2.Player interface proxy object

exception omxplayer.dbus_connection.DBusConnectionError[source]

Bases: Exception

Connection error raised when DBusConnection can’t set up a connection

class omxplayer.dbus_connection.DbusObject(object_proxy, property_manager, interface_name, methods, properties)[source]

Bases: object

omxplayer.keys

omxplayer.keys.BLANK = 24
omxplayer.keys.DECREASE_SPEED = 1
omxplayer.keys.DECREASE_SUBTITLE_DELAY = 13
omxplayer.keys.DECREASE_VOLUME = 17
omxplayer.keys.EXIT = 15
omxplayer.keys.FAST_FORWARD = 4
omxplayer.keys.HIDE_SUBTITLES = 30
omxplayer.keys.HIDE_VIDEO = 28
omxplayer.keys.INCREASE_SPEED = 2
omxplayer.keys.INCREASE_SUBTITLE_DELAY = 14
omxplayer.keys.INCREASE_VOLUME = 18
omxplayer.keys.MOVE_VIDEO = 27
omxplayer.keys.NEXT_AUDIO = 7
omxplayer.keys.NEXT_CHAPTER = 9
omxplayer.keys.NEXT_SUBTITLE = 11
omxplayer.keys.PAUSE = 16
omxplayer.keys.PREVIOUS_AUDIO = 6
omxplayer.keys.PREVIOUS_CHAPTER = 8
omxplayer.keys.PREVIOUS_SUBTITLE = 10
omxplayer.keys.REWIND = 3
omxplayer.keys.SEEK_ABSOLUTE = 26
omxplayer.keys.SEEK_BACK_LARGE = 21
omxplayer.keys.SEEK_BACK_SMALL = 19
omxplayer.keys.SEEK_FORWARD_LARGE = 22
omxplayer.keys.SEEK_FORWARD_SMALL = 20
omxplayer.keys.SEEK_RELATIVE = 25
omxplayer.keys.SET_ALPHA = 32
omxplayer.keys.SHOW_INFO = 5
omxplayer.keys.SHOW_SUBTITLES = 31
omxplayer.keys.STEP = 23
omxplayer.keys.TOGGLE_SUBTITLE = 12
omxplayer.keys.UNHIDE_VIDEO = 29