Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2012-09-14 12:30:08 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2012-10-15 19:24:33 (GMT)
commit2a73e7bf257c1629f5d12a4f71947495f811f185 (patch)
tree643b2bd315ba9fd9c1bf22334eaf6298bb644058
parentacf5b660d31064bda1f654579a8ca274c792e8fb (diff)
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@gmail.com>
-rw-r--r--jukeboxactivity.py33
1 files 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):