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-10-02 19:38:14 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2012-10-10 16:24:37 (GMT)
commit3ac69625c4ec6cca261f9925793b6657a37a0031 (patch)
treefd5bc87902625e7dbb0e521987856ccb7795fd2d
parente56a24ab0ecd550b5c084655da367f42d8df76c6 (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.py31
1 files changed, 13 insertions, 18 deletions
diff --git a/jukeboxactivity.py b/jukeboxactivity.py
index 97c2de4..11e1331 100644
--- a/jukeboxactivity.py
+++ b/jukeboxactivity.py
@@ -169,12 +169,20 @@ 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:
@@ -269,12 +277,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://'):
@@ -289,7 +291,7 @@ class JukeboxActivity(activity.Activity):
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)
@@ -517,16 +519,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:
@@ -538,6 +530,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()
@@ -728,6 +721,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):