Verified Commit f9ce0391 authored by Fabio Manganiello's avatar Fabio Manganiello
Browse files

FIX: Various omxplayer fixes

- Better synchronization with the player upon `play` request - wait until the play started event is received before returning the status

- DBus exceptions should be caught and handled in the status call
parent c3681e7b
Pipeline #82 passed with stages
in 5 minutes and 23 seconds
......@@ -12,6 +12,12 @@ Given the high speed of development in the first phase, changes are being report
method (closes #115).
- Support for custom YouTube video/audio formats on media plugins.
### Fixed
- Responses for requests received over an MQTT backend are now delivered to the right topic
(`<device_base_topic>/responses/<msg_id>`).
- Various fixes on media plugins.
## [0.22.3] - 2021-10-01
### Added
......
......@@ -25,13 +25,14 @@ class MediaOmxplayerPlugin(MediaPlugin):
* **omxplayer-wrapper** (``pip install omxplayer-wrapper``)
"""
def __init__(self, args=None, *argv, **kwargs):
def __init__(self, args=None, *argv, timeout: float = 20., **kwargs):
"""
:param args: Arguments that will be passed to the OMXPlayer constructor
(e.g. subtitles, volume, start position, window size etc.) see
https://github.com/popcornmix/omxplayer#synopsis and
https://python-omxplayer-wrapper.readthedocs.io/en/latest/omxplayer/#omxplayer.player.OMXPlayer
:type args: list
:param timeout: How long the plugin should wait for a video to start upon play request (default: 20 seconds).
"""
super().__init__(*argv, **kwargs)
......@@ -40,6 +41,7 @@ class MediaOmxplayerPlugin(MediaPlugin):
args = []
self.args = args
self.timeout = timeout
self._player = None
self._handlers = {e.value: [] for e in PlayerEvent}
self._play_started = threading.Event()
......@@ -95,6 +97,8 @@ class MediaOmxplayerPlugin(MediaPlugin):
self._post_event(MediaPlayEvent, resource=resource)
self._init_player_handlers()
if not self._play_started.wait(timeout=self.timeout):
self.logger.warning(f'The player has not sent a play started event within {self.timeout}')
return self.status()
@action
......@@ -308,6 +312,7 @@ class MediaOmxplayerPlugin(MediaPlugin):
"""
from omxplayer.player import OMXPlayerDeadError
from dbus import DBusException
if not self._player:
return {
......@@ -316,8 +321,11 @@ class MediaOmxplayerPlugin(MediaPlugin):
try:
state = self._player.playback_status().lower()
except OMXPlayerDeadError:
self._player = None
except (OMXPlayerDeadError, DBusException) as e:
self.logger.warning(f'Could not retrieve player status: {e}')
if isinstance(e, OMXPlayerDeadError):
self._player = None
return {
'state': PlayerState.STOP.value
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment