From c3681e7b2a25fac1787d9952f33db2e06642f7a2 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 17 Oct 2021 16:38:38 +0200 Subject: [PATCH] FIX: Don't try and set the volume of the omxplayer when the instance may not be ready yet --- platypush/plugins/media/omxplayer/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/platypush/plugins/media/omxplayer/__init__.py b/platypush/plugins/media/omxplayer/__init__.py index 967dabc59..3ce2d1931 100644 --- a/platypush/plugins/media/omxplayer/__init__.py +++ b/platypush/plugins/media/omxplayer/__init__.py @@ -1,4 +1,5 @@ import enum +import threading import urllib.parse from platypush.context import get_bus @@ -41,6 +42,7 @@ class MediaOmxplayerPlugin(MediaPlugin): self.args = args self._player = None self._handlers = {e.value: [] for e in PlayerEvent} + self._play_started = threading.Event() @action def play(self, resource=None, subtitles=None, *args, **kwargs): @@ -63,6 +65,8 @@ class MediaOmxplayerPlugin(MediaPlugin): self._player.play() return self.status() + else: + self._play_started.clear() self._post_event(MediaPlayRequestEvent, resource=resource) @@ -89,12 +93,8 @@ class MediaOmxplayerPlugin(MediaPlugin): 'be able to control the media') self.logger.exception(e) - if self.volume: - self.set_volume(self.volume) - self._post_event(MediaPlayEvent, resource=resource) self._init_player_handlers() - return self.status() @action @@ -359,6 +359,10 @@ class MediaOmxplayerPlugin(MediaPlugin): def on_play(self): def _f(player): + if self.volume and not self._play_started.is_set(): + self.set_volume(self.volume) + self._play_started.set() + resource = player.get_source() self._post_event(MediaPlayEvent, resource=resource) for callback in self._handlers[PlayerEvent.PLAY.value]: