From 05abc86b908b1566f328dcd786115837321259db Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 4 Feb 2019 01:55:14 +0100 Subject: [PATCH] Handling webtorrent instance stop from mplayer interface --- platypush/plugins/media/mplayer.py | 15 +++++++++++++++ platypush/plugins/media/webtorrent.py | 3 --- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/platypush/plugins/media/mplayer.py b/platypush/plugins/media/mplayer.py index 01f763f7..585fe2b0 100644 --- a/platypush/plugins/media/mplayer.py +++ b/platypush/plugins/media/mplayer.py @@ -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 diff --git a/platypush/plugins/media/webtorrent.py b/platypush/plugins/media/webtorrent.py index 5285f30e..0a049144 100644 --- a/platypush/plugins/media/webtorrent.py +++ b/platypush/plugins/media/webtorrent.py @@ -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()