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