Reload logic on media.ctrl in case the connection with the media plugin has been reset

This commit is contained in:
Fabio Manganiello 2018-04-22 23:39:23 +02:00
parent 6ef97e9ddc
commit c4401b25be

View file

@ -64,7 +64,10 @@ class MediaCtrlPlugin(Plugin):
try: try:
player = get_plugin(plugin) player = get_plugin(plugin)
except: except:
continue try:
player = get_plugin(plugin, reload=True)
except:
continue
status = player.status().output status = player.status().output
if status['state'] == PlayerState.PLAY.value or status['state'] == PlayerState.PAUSE.value: if status['state'] == PlayerState.PLAY.value or status['state'] == PlayerState.PAUSE.value:
@ -76,13 +79,22 @@ class MediaCtrlPlugin(Plugin):
def play(self, url): def play(self, url):
(type, resource) = self._get_type_and_resource_by_url(url) (type, resource) = self._get_type_and_resource_by_url(url)
response = Response(output='', errors = []) response = Response(output='', errors = [])
plugin_name = None
if type == 'mpd': if type == 'mpd':
self.plugin = get_plugin('music.mpd') plugin_name = 'music.mpd'
elif type == 'youtube:video' or type == 'file': elif type == 'youtube:video' or type == 'file':
self.plugin = get_plugin('video.omxplayer') plugin_name = 'video.omxplayer'
elif type == 'torrent': elif type == 'torrent':
self.plugin = get_plugin('video.torrentcast') plugin_name = 'video.torrentcast'
if not plugin_name:
raise RuntimeError("Unsupported type '{}'".format(type))
try:
self.plugin = get_plugin(plugin_name)
except:
self.plugin = get_plugin(plugin_name, reload=True)
self.url = resource self.url = resource
return self.plugin.play(resource) return self.plugin.play(resource)