Made OMXPlayer plugin more resiliant in the case where the player has already terminated

This commit is contained in:
Fabio Manganiello 2019-07-13 22:12:50 +02:00
parent 0b05d7d8de
commit 55cd937a51

View file

@ -92,17 +92,21 @@ class MediaOmxplayerPlugin(MediaPlugin):
@action @action
def stop(self): def stop(self):
""" Stop the playback """ """ Stop the playback (same as quit) """
if self._player: return self.quit()
self._player.stop()
return {'status': 'stop'}
@action @action
def quit(self): def quit(self):
""" Quit the player """ """ Quit the player """
from omxplayer.player import OMXPlayerDeadError
if self._player: if self._player:
try:
self._player.stop() self._player.stop()
self._player.quit() self._player.quit()
except OMXPlayerDeadError:
pass
self._player = None self._player = None
return {'status': 'stop'} return {'status': 'stop'}
@ -271,8 +275,21 @@ class MediaOmxplayerPlugin(MediaPlugin):
} }
""" """
if self._player: from omxplayer.player import OMXPlayerDeadError
if not self._player:
return {
'state': PlayerState.STOP.value
}
try:
state = self._player.playback_status().lower() state = self._player.playback_status().lower()
except OMXPlayerDeadError:
self._player = None
return {
'state': PlayerState.STOP.value
}
if state == 'playing': if state == 'playing':
state = PlayerState.PLAY.value state = PlayerState.PLAY.value
elif state == 'stopped': elif state == 'stopped':
@ -295,10 +312,6 @@ class MediaOmxplayerPlugin(MediaPlugin):
'volume': self._player.volume() * 100, 'volume': self._player.volume() * 100,
'volume_max': 100, 'volume_max': 100,
} }
else:
return {
'state': PlayerState.STOP.value
}
def add_handler(self, event_type, callback): def add_handler(self, event_type, callback):
if event_type not in self._handlers.keys(): if event_type not in self._handlers.keys():