From 8fa20806525098b16e0589b4af83ada73dd74bdb Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 21 Oct 2024 21:07:27 +0200 Subject: [PATCH] [media.vlc] A more robust logic for the player monitor thread. The player may sometimes stop, or the VLC instance crash, without sending a stop event. This may leave the Platypush plugin in a PLAYING state, and the instance may not be properly cleaned up. This commit adds a polling logic to the monitor thread to verify every second if the player is still running, and terminate the instance if that's not the case. --- platypush/plugins/media/vlc/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/platypush/plugins/media/vlc/__init__.py b/platypush/plugins/media/vlc/__init__.py index e60ea62a08..caf3ae30da 100644 --- a/platypush/plugins/media/vlc/__init__.py +++ b/platypush/plugins/media/vlc/__init__.py @@ -124,7 +124,15 @@ class MediaVlcPlugin(MediaPlugin): self._player.set_media(self._instance.media_new(resource.resource)) def _player_monitor(self): - self._on_stop_event.wait() + import vlc + + while True: + self._on_stop_event.wait(1) + if self._player: + state = self._player.get_state() + if state in {vlc.State.Stopped, vlc.State.Ended, vlc.State.Error}: # type: ignore + break + self.logger.info('VLC stream terminated') self.quit()