Handling webtorrent instance stop from mplayer interface
This commit is contained in:
parent
286eb431f0
commit
05abc86b90
2 changed files with 15 additions and 3 deletions
|
@ -74,6 +74,7 @@ class MediaMplayerPlugin(MediaPlugin):
|
||||||
self._build_actions()
|
self._build_actions()
|
||||||
self._mplayer = None
|
self._mplayer = None
|
||||||
self._mplayer_timeout = mplayer_timeout
|
self._mplayer_timeout = mplayer_timeout
|
||||||
|
self._is_playing_torrent = False
|
||||||
|
|
||||||
|
|
||||||
def _init_mplayer_bin(self, mplayer_bin=None):
|
def _init_mplayer_bin(self, mplayer_bin=None):
|
||||||
|
@ -227,6 +228,9 @@ class MediaMplayerPlugin(MediaPlugin):
|
||||||
return
|
return
|
||||||
|
|
||||||
self._mplayer.wait()
|
self._mplayer.wait()
|
||||||
|
try: self.quit()
|
||||||
|
except: pass
|
||||||
|
|
||||||
get_bus().post(MediaStopEvent())
|
get_bus().post(MediaStopEvent())
|
||||||
self._mplayer = None
|
self._mplayer = None
|
||||||
|
|
||||||
|
@ -249,8 +253,10 @@ class MediaMplayerPlugin(MediaPlugin):
|
||||||
if resource.startswith('file://'):
|
if resource.startswith('file://'):
|
||||||
resource = resource[7:]
|
resource = resource[7:]
|
||||||
elif resource.startswith('magnet:?'):
|
elif resource.startswith('magnet:?'):
|
||||||
|
self._is_playing_torrent = True
|
||||||
return get_plugin('media.webtorrent').play(resource)
|
return get_plugin('media.webtorrent').play(resource)
|
||||||
|
|
||||||
|
self._is_playing_torrent = False
|
||||||
return self._exec('loadfile', resource, mplayer_args=mplayer_args)
|
return self._exec('loadfile', resource, mplayer_args=mplayer_args)
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
@ -258,6 +264,14 @@ class MediaMplayerPlugin(MediaPlugin):
|
||||||
""" Toggle the paused state """
|
""" Toggle the paused state """
|
||||||
return self._exec('pause')
|
return self._exec('pause')
|
||||||
|
|
||||||
|
def _stop_torrent(self):
|
||||||
|
if self._is_playing_torrent:
|
||||||
|
try:
|
||||||
|
get_plugin('media.webtorrent').quit()
|
||||||
|
except:
|
||||||
|
self.logger.warning('Cannot quit the webtorrent instance: {}'.
|
||||||
|
format(str(e)))
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def stop(self):
|
def stop(self):
|
||||||
""" Stop the playback """
|
""" Stop the playback """
|
||||||
|
@ -266,6 +280,7 @@ class MediaMplayerPlugin(MediaPlugin):
|
||||||
@action
|
@action
|
||||||
def quit(self):
|
def quit(self):
|
||||||
""" Quit the player """
|
""" Quit the player """
|
||||||
|
self._stop_torrent()
|
||||||
self._exec('quit')
|
self._exec('quit')
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
|
|
@ -169,9 +169,6 @@ class MediaWebtorrentPlugin(MediaPlugin):
|
||||||
@action
|
@action
|
||||||
def quit(self):
|
def quit(self):
|
||||||
""" Quit the player """
|
""" Quit the player """
|
||||||
if self._media_plugin:
|
|
||||||
self._media_plugin.quit()
|
|
||||||
|
|
||||||
if self._webtorrent_process and self._is_process_alive(
|
if self._webtorrent_process and self._is_process_alive(
|
||||||
self._webtorrent_process.pid):
|
self._webtorrent_process.pid):
|
||||||
self._webtorrent_process.terminate()
|
self._webtorrent_process.terminate()
|
||||||
|
|
Loading…
Reference in a new issue