[Sugar-devel] [PATCH Jukebox] Stop player on focus lost
Gonzalo Odiard
gonzalo at laptop.org
Mon Aug 27 16:00:01 EDT 2012
Thanks, pushed in sugar-0.94 branch.
Gonzalo
On Mon, Aug 27, 2012 at 2:28 PM, Manuel Kaufmann <humitos at gmail.com> wrote:
> Stop the player when the user is reproducing a video and switch to
> another activity.
>
> Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
> ---
> jukeboxactivity.py | 23 ++++++++++++++++++++---
> 1 file changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/jukeboxactivity.py b/jukeboxactivity.py
> index e900263..cb116a8 100644
> --- a/jukeboxactivity.py
> +++ b/jukeboxactivity.py
> @@ -131,6 +131,11 @@ class JukeboxActivity(activity.Activity):
> toolbar_box.show_all()
> 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
> + # reproducing the video
> + self.connect("notify::active", self._notify_active_cb)
> +
> if handle.uri:
> pass
> elif self._shared_activity:
> @@ -155,7 +160,6 @@ class JukeboxActivity(activity.Activity):
> self.playflag = False
> self.tags = {}
> self.only_audio = False
> - self.got_stream_info = False
>
> self.tag_reader = TagReader()
> self.tag_reader.connect('get-tags', self.__get_tags_cb)
> @@ -187,6 +191,20 @@ class JukeboxActivity(activity.Activity):
> self.uri = handle.uri
> gobject.idle_add(self._start, self.uri, handle.title)
>
> + 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 is not None and not self.only_audio:
> + if not self.player.is_playing() and self.props.active:
> + self.player.play()
> + if self.player.is_playing() and not self.props.active:
> + self.player.pause()
> +
> def _switch_canvas(self, show_video):
> """Show or hide the video visualization in the canvas.
>
> @@ -333,7 +351,7 @@ class JukeboxActivity(activity.Activity):
> self.tags[gst.TAG_ARTIST], album)
>
> def _player_stream_info_cb(self, widget, stream_info):
> - if not len(stream_info) or self.got_stream_info:
> + if not len(stream_info):
> return
>
> GST_STREAM_TYPE_UNKNOWN = 0
> @@ -346,7 +364,6 @@ class JukeboxActivity(activity.Activity):
> if item.props.type == GST_STREAM_TYPE_VIDEO:
> only_audio = False
> self.only_audio = only_audio
> - self.got_stream_info = True
> self._update_overlay()
>
> def _joined_cb(self, activity):
> --
> 1.7.11.4
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20120827/e3f4bf5b/attachment-0001.html>
More information about the Sugar-devel
mailing list