From 8618a200d1039d18730128f15c8dd412b9e187ad Mon Sep 17 00:00:00 2001 From: Nokse22 <44558032+Nokse22@users.noreply.github.com> Date: Sat, 1 Jun 2024 19:19:42 +0200 Subject: [PATCH] improved query duration/position --- src/window.py | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/window.py b/src/window.py index b086211..9228cb9 100644 --- a/src/window.py +++ b/src/window.py @@ -339,26 +339,19 @@ def update_slider(self, *args): if not self.player_object.is_playing: return False # cancel timeout else: - success, self.duration = self.player_object.query_duration(Gst.Format.TIME) - if not success: - end_value = 100 - pass - else: - end_value = self.duration / Gst.SECOND - self.progress_bar.set_range(0, end_value) - - self.duration_label.set_label(utils.pretty_duration(end_value)) - - success, position = self.player_object.query_position(Gst.Format.TIME) - if not success: - pass - else: - position = position / Gst.SECOND - self.progress_bar.get_adjustment().set_value(position) - self.small_progress_bar.set_fraction(position/end_value) - self.previous_time = position - - self.time_played_label.set_label(utils.pretty_duration(position)) + self.duration = self.player_object.query_duration() + end_value = self.duration / Gst.SECOND + self.progress_bar.set_range(0, end_value) + + self.duration_label.set_label(utils.pretty_duration(end_value)) + + position = self.player_object.query_position() + position = position / Gst.SECOND + self.progress_bar.get_adjustment().set_value(position) + self.small_progress_bar.set_fraction(position/end_value) + self.previous_time = position + + self.time_played_label.set_label(utils.pretty_duration(position)) return True @Gtk.Template.Callback("on_lyrics_button_clicked")