Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/controls.py
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2013-01-25 22:19:08 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2013-01-29 13:41:49 (GMT)
commitf2c441717877db34d36cb7925afeacb1e4d03d50 (patch)
tree998160024ad5b24577989166148e2d34f65d0e6c /controls.py
parent0cb00f08dcba526cba9a8ca96ad9c5e54c6a88b9 (diff)
Set total_time just once per stream
When the 'play' signal is emitted, we ask for the duration of the stream until we get it. Then, we set it into the label and stop the GObject.timeout_add. Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
Diffstat (limited to 'controls.py')
-rw-r--r--controls.py34
1 files changed, 23 insertions, 11 deletions
diff --git a/controls.py b/controls.py
index 119095c..6d50946 100644
--- a/controls.py
+++ b/controls.py
@@ -33,6 +33,7 @@ class Controls(GObject.GObject):
add, remove, etc) toolbar"""
SCALE_UPDATE_INTERVAL = 1000
+ SCALE_DURATION_TEXT = 100
RESEEK_TIMEOUT = 250 # ms
def __init__(self, activity, toolbar):
@@ -125,9 +126,30 @@ class Controls(GObject.GObject):
if self._scale_update_id == -1:
self._scale_update_id = GObject.timeout_add(
self.SCALE_UPDATE_INTERVAL, self.__update_scale_cb)
+
+ # We need to wait for GstPlayer to load the stream's duration
+ GObject.timeout_add(self.SCALE_DURATION_TEXT,
+ self.__set_scale_duration)
+
self.set_enabled()
self.set_button_pause()
+ def __set_scale_duration(self):
+ success, self.p_position, self.p_duration = \
+ self.activity.player.query_position()
+
+ if success and self.p_duration != Gst.CLOCK_TIME_NONE:
+ seconds = self.p_duration * 10 ** -9
+ time = '%2d:%02d' % (int(seconds / 60), int(seconds % 60))
+ self.total_time_label.set_text(time)
+ # Once we set the total_time we don't need to change it
+ # until a new stream is played
+ return False
+ else:
+ # We don't have the stream's duration yet, we need to call
+ # this method again
+ return True
+
def __open_button_clicked_cb(self, widget):
self.show_picker_cb()
@@ -278,10 +300,7 @@ class Controls(GObject.GObject):
success, self.p_position, self.p_duration = \
self.activity.player.query_position()
- if not success:
- return True
-
- if self.p_position != Gst.CLOCK_TIME_NONE:
+ if success and self.p_position != Gst.CLOCK_TIME_NONE:
value = self.p_position * 100.0 / self.p_duration
self.adjustment.set_value(value)
@@ -290,13 +309,6 @@ class Controls(GObject.GObject):
time = '%2d:%02d' % (int(seconds / 60), int(seconds % 60))
self.current_time_label.set_text(time)
- # FIXME: this should be updated just once when the file starts
- # the first time
- if self.p_duration != Gst.CLOCK_TIME_NONE:
- seconds = self.p_duration * 10 ** -9
- time = '%2d:%02d' % (int(seconds / 60), int(seconds % 60))
- self.total_time_label.set_text(time)
-
return True
def __playlist_finished_cb(self, widget):