Made OMXPlayer plugin more resiliant in the case where the player has already terminated
This commit is contained in:
parent
0b05d7d8de
commit
55cd937a51
1 changed files with 43 additions and 30 deletions
|
@ -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:
|
||||||
self._player.stop()
|
try:
|
||||||
self._player.quit()
|
self._player.stop()
|
||||||
|
self._player.quit()
|
||||||
|
except OMXPlayerDeadError:
|
||||||
|
pass
|
||||||
|
|
||||||
self._player = None
|
self._player = None
|
||||||
|
|
||||||
return {'status': 'stop'}
|
return {'status': 'stop'}
|
||||||
|
@ -271,35 +275,44 @@ class MediaOmxplayerPlugin(MediaPlugin):
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self._player:
|
from omxplayer.player import OMXPlayerDeadError
|
||||||
state = self._player.playback_status().lower()
|
|
||||||
if state == 'playing':
|
|
||||||
state = PlayerState.PLAY.value
|
|
||||||
elif state == 'stopped':
|
|
||||||
state = PlayerState.STOP.value
|
|
||||||
elif state == 'paused':
|
|
||||||
state = PlayerState.PAUSE.value
|
|
||||||
|
|
||||||
return {
|
if not self._player:
|
||||||
'duration': self._player.duration(),
|
|
||||||
'filename': urllib.parse.unquote(self._player.get_source()).split('/')[-1] if self._player.get_source().startswith('file://') else None,
|
|
||||||
'fullscreen': self._player.fullscreen(),
|
|
||||||
'mute': self._player._is_muted,
|
|
||||||
'path': self._player.get_source(),
|
|
||||||
'pause': state == PlayerState.PAUSE.value,
|
|
||||||
'position': max(0, self._player.position()),
|
|
||||||
'seekable': self._player.can_seek(),
|
|
||||||
'state': state,
|
|
||||||
'title': urllib.parse.unquote(self._player.get_source()).split('/')[-1] if self._player.get_source().startswith('file://') else None,
|
|
||||||
'url': self._player.get_source(),
|
|
||||||
'volume': self._player.volume() * 100,
|
|
||||||
'volume_max': 100,
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
return {
|
return {
|
||||||
'state': PlayerState.STOP.value
|
'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':
|
||||||
|
state = PlayerState.STOP.value
|
||||||
|
elif state == 'paused':
|
||||||
|
state = PlayerState.PAUSE.value
|
||||||
|
|
||||||
|
return {
|
||||||
|
'duration': self._player.duration(),
|
||||||
|
'filename': urllib.parse.unquote(self._player.get_source()).split('/')[-1] if self._player.get_source().startswith('file://') else None,
|
||||||
|
'fullscreen': self._player.fullscreen(),
|
||||||
|
'mute': self._player._is_muted,
|
||||||
|
'path': self._player.get_source(),
|
||||||
|
'pause': state == PlayerState.PAUSE.value,
|
||||||
|
'position': max(0, self._player.position()),
|
||||||
|
'seekable': self._player.can_seek(),
|
||||||
|
'state': state,
|
||||||
|
'title': urllib.parse.unquote(self._player.get_source()).split('/')[-1] if self._player.get_source().startswith('file://') else None,
|
||||||
|
'url': self._player.get_source(),
|
||||||
|
'volume': self._player.volume() * 100,
|
||||||
|
'volume_max': 100,
|
||||||
|
}
|
||||||
|
|
||||||
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():
|
||||||
raise AttributeError('{} is not a valid PlayerEvent type'.
|
raise AttributeError('{} is not a valid PlayerEvent type'.
|
||||||
|
|
Loading…
Reference in a new issue