Handling webtorrent instance stop from mplayer interface

This commit is contained in:
Fabio Manganiello 2019-02-04 01:55:14 +01:00
parent 286eb431f0
commit 05abc86b90
2 changed files with 15 additions and 3 deletions

View file

@ -74,6 +74,7 @@ class MediaMplayerPlugin(MediaPlugin):
self._build_actions()
self._mplayer = None
self._mplayer_timeout = mplayer_timeout
self._is_playing_torrent = False
def _init_mplayer_bin(self, mplayer_bin=None):
@ -227,6 +228,9 @@ class MediaMplayerPlugin(MediaPlugin):
return
self._mplayer.wait()
try: self.quit()
except: pass
get_bus().post(MediaStopEvent())
self._mplayer = None
@ -249,8 +253,10 @@ class MediaMplayerPlugin(MediaPlugin):
if resource.startswith('file://'):
resource = resource[7:]
elif resource.startswith('magnet:?'):
self._is_playing_torrent = True
return get_plugin('media.webtorrent').play(resource)
self._is_playing_torrent = False
return self._exec('loadfile', resource, mplayer_args=mplayer_args)
@action
@ -258,6 +264,14 @@ class MediaMplayerPlugin(MediaPlugin):
""" Toggle the paused state """
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
def stop(self):
""" Stop the playback """
@ -266,6 +280,7 @@ class MediaMplayerPlugin(MediaPlugin):
@action
def quit(self):
""" Quit the player """
self._stop_torrent()
self._exec('quit')
@action

View file

@ -169,9 +169,6 @@ class MediaWebtorrentPlugin(MediaPlugin):
@action
def quit(self):
""" Quit the player """
if self._media_plugin:
self._media_plugin.quit()
if self._webtorrent_process and self._is_process_alive(
self._webtorrent_process.pid):
self._webtorrent_process.terminate()