From d5600d31c5eb7ed82c84743900569feb60d3c4a8 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Fri, 15 Mar 2024 10:02:55 +0100 Subject: [PATCH] properly stop the stream when switching videos --- melon/player/__init__.py | 1 + melon/widgets/player.py | 17 +++++++++++++---- po/de.po | 17 +++++++++-------- po/fa.po | 17 +++++++++-------- po/melon.pot | 17 +++++++++-------- 5 files changed, 41 insertions(+), 28 deletions(-) diff --git a/melon/player/__init__.py b/melon/player/__init__.py index b029a33..b54d1f3 100644 --- a/melon/player/__init__.py +++ b/melon/player/__init__.py @@ -71,6 +71,7 @@ class PlayerScreen(Adw.NavigationPage): if not self.player is None: self.player.connect_ended(None) self.player.connect_update(None) + self.player.stop() def on_player_end(self): if self.position is None or self.duration is None: diff --git a/melon/widgets/player.py b/melon/widgets/player.py index 13f2fb7..1623623 100644 --- a/melon/widgets/player.py +++ b/melon/widgets/player.py @@ -23,6 +23,7 @@ class VideoPlayer(Gtk.Overlay): self.position = None self.duration = None self.paused = True + self.stopped = True self.update_callback=None self.ended_callback=None @@ -126,8 +127,6 @@ class VideoPlayer(Gtk.Overlay): self.picture.add_controller(self.click_ctr) self.click_ctr.connect("pressed", self._onclick) - self._start_loop() - def connect_update(self, callback=None): self.update_callback = callback def connect_ended(self, callback=None): @@ -182,6 +181,9 @@ class VideoPlayer(Gtk.Overlay): self.select_stream(stream) def _start_loop(self): + if not self.stopped: + return + self.stopped = False # run once every second GLib.timeout_add(1000, self._loop) def _loop(self): @@ -225,8 +227,9 @@ class VideoPlayer(Gtk.Overlay): elif not dur is None: self.set_duration(dur) - # stop the loop if paused? - return True + # returns false if the video was stopped + # which will stop the loop + return not self.stopped def set_position_and_duration(self, pos, dur): self.position = pos @@ -267,6 +270,7 @@ class VideoPlayer(Gtk.Overlay): def play(self): self.paused = False + self._start_loop() self.source.set_state(Gst.State.PLAYING) # show pause button # because if playing the onclick action is to pause @@ -277,6 +281,11 @@ class VideoPlayer(Gtk.Overlay): # show play button # because if paused the onclick action is to start playing self.playpause_display.update("", "media-playback-start-symbolic", tooltip=_("Play")) + def stop(self): + self.paused = True + self.stopped = True + self.source.set_state(Gst.State.NULL) + self.playpause_display.update("", "media-playback-start-symbolic", tooltip=_("Play")) def _toggle_playpause(self, _): if self.paused: diff --git a/po/de.po b/po/de.po index 4211fc4..b1ba893 100644 --- a/po/de.po +++ b/po/de.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Melon 0.1.2\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-03-15 09:36+0100\n" +"POT-Creation-Date: 2024-03-15 10:02+0100\n" "PO-Revision-Date: 2024-03-01 11:23+0000\n" "Last-Translator: Anonymous \n" "Language-Team: German \n" "Language-Team: Persian \n" "Language-Team: LANGUAGE \n" @@ -76,7 +76,7 @@ msgstr "" #: ../melon/browse/server.py:101 ../melon/browse/server.py:127 #: ../melon/home/history.py:23 ../melon/home/new.py:29 #: ../melon/home/playlists.py:21 ../melon/home/subs.py:20 -#: ../melon/importer.py:61 ../melon/player/__init__.py:101 +#: ../melon/importer.py:61 ../melon/player/__init__.py:102 #: ../melon/player/playlist.py:158 ../melon/player/playlist.py:165 #: ../melon/playlist/__init__.py:50 msgid "*crickets chirping*" @@ -336,11 +336,11 @@ msgstr "" msgid "Add this video to a playlist" msgstr "" -#: ../melon/player/__init__.py:103 +#: ../melon/player/__init__.py:104 msgid "Video could not be loaded" msgstr "" -#: ../melon/player/__init__.py:140 ../melon/player/__init__.py:174 +#: ../melon/player/__init__.py:141 ../melon/player/__init__.py:175 #: ../melon/player/playlist.py:51 msgid "Loading..." msgstr "" @@ -707,19 +707,20 @@ msgid "" "Disabled servers won't show up in the browser or on the local/home screen" msgstr "" -#: ../melon/widgets/player.py:34 +#: ../melon/widgets/player.py:35 msgid "No streams available" msgstr "" -#: ../melon/widgets/player.py:80 ../melon/widgets/player.py:279 +#: ../melon/widgets/player.py:81 ../melon/widgets/player.py:283 +#: ../melon/widgets/player.py:288 msgid "Play" msgstr "" -#: ../melon/widgets/player.py:101 +#: ../melon/widgets/player.py:102 msgid "Video quality" msgstr "" -#: ../melon/widgets/player.py:273 +#: ../melon/widgets/player.py:277 msgid "Pause" msgstr "" -- 2.38.5