From 749436c452fd2f95a6753c6309a651e33b8f4f40 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 21 Feb 2019 19:24:43 +0100 Subject: [PATCH] Clean up running VLC instance on stop and new media play --- platypush/plugins/media/vlc.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/platypush/plugins/media/vlc.py b/platypush/plugins/media/vlc.py index c4b2ea3e..b3725c3c 100644 --- a/platypush/plugins/media/vlc.py +++ b/platypush/plugins/media/vlc.py @@ -37,12 +37,10 @@ class MediaVlcPlugin(MediaPlugin): :type volume: int """ - import vlc - super().__init__(*argv, **kwargs) self._args = args or [] - self._instance = vlc.Instance(*self._args) + self._instance = None self._player = None self._latest_seek = None self._default_fullscreen = fullscreen @@ -65,19 +63,29 @@ class MediaVlcPlugin(MediaPlugin): ] if hasattr(vlc.EventType, evt)] def _init_vlc(self, resource): - if self._player: - self._player.stop() - self._player = None + import vlc + self._reset_state() for k,v in self._env.items(): os.environ[k] = v + self._instance = vlc.Instance(*self._args) self._player = self._instance.media_player_new(resource) for evt in self._watched_event_types(): self._player.event_manager().event_attach( eventtype=evt, callback=self._event_callback()) + def _reset_state(self): + self._latest_seek = None + if self._player: + self._player.release() + self._player = None + + if self._instance: + self._instance.release() + self._instance = None + def _event_callback(self): def callback(event): from vlc import EventType @@ -90,11 +98,8 @@ class MediaVlcPlugin(MediaPlugin): bus.post(MediaPauseEvent()) elif event.type == EventType.MediaPlayerStopped or \ event.type == EventType.MediaPlayerEndReached: + self._reset_state() bus.post(MediaStopEvent()) - if self._player: - self._player.release() - self._player = None - self._latest_seek = None for callback in self._on_stop_callbacks: callback() elif event.type == EventType.MediaPlayerTitleChanged: