diff --git a/app/tools/media.py b/app/tools/media.py index 1f2313c7..cef65066 100644 --- a/app/tools/media.py +++ b/app/tools/media.py @@ -1,3 +1,4 @@ +from app.commons import run_task from app.tools import vlc @@ -15,13 +16,14 @@ class Player: _VLC_INSTANCE = vlc.Instance("--quiet --no-xlib").media_player_new() return _VLC_INSTANCE + @run_task def play(self, mrl=None): - if not self._is_playing: - if mrl: - self._player.set_mrl(mrl) - self._player.play() - self._is_playing = True + if mrl: + self._player.set_mrl(mrl) + self._player.play() + self._is_playing = True + @run_task def stop(self): if self._is_playing: self._player.stop() @@ -30,6 +32,7 @@ class Player: def pause(self): self._player.pause() + @run_task def release(self): if self._player: self._is_playing = False diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index 7a5d730c..b11c186a 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -248,6 +248,13 @@ class Application(Gtk.Application): self._main_window.set_application(self) self._main_window.present() + def do_shutdown(self): + """ Performs shutdown tasks """ + write_config(self._options) # storing current config + if self._player: + self._player.release() + Gtk.Application.do_shutdown(self) + def init_drag_and_drop(self): """ Enable drag-and-drop """ target = [] @@ -276,9 +283,6 @@ class Application(Gtk.Application): @run_idle def on_close_app(self, *args): - """ Called before app quit """ - write_config(self._options) # storing current config - self.on_player_close() self.quit() def on_resize(self, window): @@ -1276,10 +1280,6 @@ class Application(Gtk.Application): self._player_box.set_size_request(w * 0.6, -1) self._player_box.set_visible(True) - - if self._player.is_playing(): - self.on_player_stop() - GLib.idle_add(self._player.play, url, priority=GLib.PRIORITY_LOW) def get_stream_url(self):