From f9ce03919b3fc4e77d476766a10c7c8cfcd8dc5b Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 17 Oct 2021 16:54:57 +0200 Subject: [PATCH] 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 --- CHANGELOG.md | 6 ++++++ platypush/plugins/media/omxplayer/__init__.py | 14 +++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11b686bcc..70de3512c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 + (`/responses/`). +- Various fixes on media plugins. + ## [0.22.3] - 2021-10-01 ### Added diff --git a/platypush/plugins/media/omxplayer/__init__.py b/platypush/plugins/media/omxplayer/__init__.py index 3ce2d1931..d9eb868e9 100644 --- a/platypush/plugins/media/omxplayer/__init__.py +++ b/platypush/plugins/media/omxplayer/__init__.py @@ -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 }