[Pkg-sugar-commit] [sugar-jukebox-activity] 07/10: Create GstPlayer just once
Jonas Smedegaard
dr at jones.dk
Sat Jun 27 01:57:03 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag v26.1
in repository sugar-jukebox-activity.
commit 2a73e7bf257c1629f5d12a4f71947495f811f185
Author: Manuel Kaufmann <humitos at gmail.com>
Date: Fri Sep 14 09:30:08 2012 -0300
Create GstPlayer just once
Instanciating GstPlayer when Jukebox is launched and changing its uri
when a new stream is played. This allow us to change between different
streams in the playlist without having many memory issues regarding
video playing in HD.
To change the stream being played in the GstPlayer instance we firstly
set the state of it to STATE_PAUSED, then to STATE_NULL and finally we
change the uri. When this process finishes we change the state again
to STATE_PLAYING.
Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
---
jukeboxactivity.py | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/jukeboxactivity.py b/jukeboxactivity.py
index ea1f95a..dc439b3 100644
--- a/jukeboxactivity.py
+++ b/jukeboxactivity.py
@@ -47,6 +47,7 @@ import pygtk
pygtk.require('2.0')
import gobject
+gobject.threads_init()
import pygst
pygst.require('0.10')
@@ -191,12 +192,21 @@ class JukeboxActivity(activity.Activity):
self.uri = handle.uri
gobject.idle_add(self._start, self.uri, handle.title)
+ # Create the player just once
+ logging.debug('Instantiating GstPlayer')
+ self.player = GstPlayer(self.videowidget)
+ self.player.connect("eos", self._player_eos_cb)
+ self.player.connect("error", self._player_error_cb)
+ self.player.connect("tag", self._player_new_tag_cb)
+ self.player.connect("stream-info", self._player_stream_info_cb)
+
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 self.player.player.props.uri 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:
@@ -290,12 +300,6 @@ class JukeboxActivity(activity.Activity):
def play(self, media_index):
self._switch_canvas(show_video=True)
self.currentplaying = media_index
- self.player.stop()
- self.player = GstPlayer(self.videowidget)
- self.player.connect("eos", self._player_eos_cb)
- self.player.connect("error", self._player_error_cb)
- self.player.connect("tag", self._player_new_tag_cb)
- self.player.connect("stream-info", self._player_stream_info_cb)
url = self.playlist[self.currentplaying]['url']
error = None
if url.startswith('journal://'):
@@ -308,7 +312,7 @@ class JukeboxActivity(activity.Activity):
self.check_if_next_prev()
if error is None:
self.player.set_uri(url)
- self.play_toggled()
+ self.player.play()
else:
self.control.set_disabled()
self._show_error_alert(_('Error'), error)
@@ -533,16 +537,6 @@ class JukeboxActivity(activity.Activity):
if not error:
self.tag_reader.set_file(url, len(self.playlist) - 1)
- if not self.player:
- # lazy init the player so that videowidget is realized
- # and has a valid widget allocation
- self._switch_canvas(show_video=True)
- self.player = GstPlayer(self.videowidget)
- self.player.connect("eos", self._player_eos_cb)
- self.player.connect("error", self._player_error_cb)
- self.player.connect("tag", self._player_new_tag_cb)
- self.player.connect("stream-info", self._player_stream_info_cb)
-
self.playlist_widget.update(self.playlist)
try:
@@ -554,6 +548,7 @@ class JukeboxActivity(activity.Activity):
url = 'file://' + jobject.file_path
self.player.set_uri(url)
+ self.player.play()
self.currentplaying = 0
self.play_toggled()
self.show_all()
@@ -744,6 +739,8 @@ class GstPlayer(gobject.GObject):
bus.connect('message', self.on_message)
def set_uri(self, uri):
+ self.player.set_state(gst.STATE_PAUSED)
+ self.player.set_state(gst.STATE_NULL)
self.player.set_property('uri', uri)
def on_sync_message(self, bus, message):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-sugar/sugar-jukebox-activity.git
More information about the pkg-sugar-commit
mailing list