[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.
This commit is contained in:
Fabio Manganiello 2024-10-21 21:07:27 +02:00
parent 25b77f068b
commit 8fa2080652
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -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()