diff options
author | Manuel Kaufmann <humitos@gmail.com> | 2013-01-24 14:49:50 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2013-01-25 12:45:14 (GMT) |
commit | 1761ace464c3bb9754128c46d524e15ed7d74e5e (patch) | |
tree | c244dd46d3a3b263c4ed90d2d03e6318e1571018 | |
parent | 0bf46d8bf132609bab93a93360e78e09f01d7b88 (diff) |
Pause Video when lost focus
If the user is playing a Video stream, this is paused if he changes
the focus to another Activity.
Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
Reviewed-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r-- | activity.py | 12 | ||||
-rw-r--r-- | player.py | 3 |
2 files changed, 11 insertions, 4 deletions
diff --git a/activity.py b/activity.py index 14fcbe9..aab843a 100644 --- a/activity.py +++ b/activity.py @@ -103,9 +103,9 @@ class JukeboxActivity(activity.Activity): self.connect("key_press_event", self._key_press_event_cb) # We want to be notified when the activity gets the focus or - # loses it. When it is not active, we don't need to keep + # loses it. When it is not active, we don't need to keep # reproducing the video - self.connect("notify::active", self._notify_active_cb) + self.connect('notify::active', self.__notify_active_cb) # FIXME: this is related with shared activity and it doesn't work # if handle.uri: @@ -172,12 +172,16 @@ class JukeboxActivity(activity.Activity): self.p_position = Gst.CLOCK_TIME_NONE self.p_duration = Gst.CLOCK_TIME_NONE - def _notify_active_cb(self, widget, event): + def __notify_active_cb(self, widget, event): """Sugar notify us that the activity is becoming active or inactive. When we are inactive, we stop the player if it is reproducing a video. """ - if self.player.player.props.uri is not None: + + logging.debug('JukeboxActivity notify::active signal received') + + if self.player.player.props.current_uri is not None and \ + self.player.playing_video(): if not self.player.is_playing() and self.props.active: self.player.play() if self.player.is_playing() and not self.props.active: @@ -180,3 +180,6 @@ class GstPlayer(GObject.GObject): def is_playing(self): return self.playing + + def playing_video(self): + return self.player.props.n_video > 0 |