[media.vlc] A more robust close/stop player logic.

This commit is contained in:
Fabio Manganiello 2024-10-13 02:36:14 +02:00
parent 9cadf98d52
commit 0ab160569a
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -53,6 +53,7 @@ class MediaVlcPlugin(MediaPlugin):
self._monitor_thread: Optional[threading.Thread] = None self._monitor_thread: Optional[threading.Thread] = None
self._on_stop_event = threading.Event() self._on_stop_event = threading.Event()
self._stop_lock = threading.RLock() self._stop_lock = threading.RLock()
self._latest_resource: Optional[MediaResource] = None
@classmethod @classmethod
def _watched_event_types(cls): def _watched_event_types(cls):
@ -135,19 +136,37 @@ class MediaVlcPlugin(MediaPlugin):
def _close_player(self): def _close_player(self):
if self._player: if self._player:
self.logger.info('Releasing VLC player resource') self.logger.info('Releasing VLC player resource')
self._player.stop()
if self._player.get_media(): try:
self._player.stop()
except Exception as e:
self.logger.warning('Could not stop the VLC player: %s', str(e))
if self._player:
try:
media = self._player.get_media()
if media:
self.logger.debug('Releasing VLC media resource') self.logger.debug('Releasing VLC media resource')
self._player.get_media().release() media.release()
except Exception as e:
self.logger.warning('Could not release the VLC media: %s', str(e))
self.logger.debug('Releasing VLC player instance') self.logger.debug('Releasing VLC player instance')
try:
self._player.release() self._player.release()
except Exception as e:
self.logger.warning('Could not release the VLC player: %s', str(e))
self._player = None self._player = None
if self._instance: if self._instance:
self.logger.info('Releasing VLC instance resource') self.logger.info('Releasing VLC instance resource')
try:
self._instance.release() self._instance.release()
except Exception as e:
self.logger.warning('Could not release the VLC instance: %s', str(e))
self._instance = None self._instance = None
@staticmethod @staticmethod