Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt/tagplay.py
diff options
context:
space:
mode:
Diffstat (limited to 'TurtleArt/tagplay.py')
-rw-r--r--TurtleArt/tagplay.py52
1 files changed, 35 insertions, 17 deletions
diff --git a/TurtleArt/tagplay.py b/TurtleArt/tagplay.py
index 72379c6..505f6f1 100644
--- a/TurtleArt/tagplay.py
+++ b/TurtleArt/tagplay.py
@@ -37,8 +37,6 @@ import gst
import gst.interfaces
import gtk
-import urllib
-
def play_audio_from_file(lc, file_path):
""" Called from Show block of audio media """
@@ -77,6 +75,24 @@ def stop_media(lc):
lc.gplay = None
+def pause_media(lc):
+ """ From pause media block """
+ if lc.gplay == None:
+ return False
+
+ if lc.gplay.player is not None:
+ lc.gplay.player.pause()
+
+
+def play_media(lc):
+ """ From play media block """
+ if lc.gplay == None:
+ return False
+
+ if lc.gplay.player is not None:
+ lc.gplay.player.play()
+
+
def media_playing(lc):
if lc.gplay == None:
return False
@@ -106,7 +122,7 @@ class Gplay():
if lc.tw.running_sugar:
self.bin.set_transient_for(lc.tw.activity)
- self.bin.move(x, y + 108)
+ self.bin.move(x, y)
self.bin.resize(w, h)
self.bin.show_all()
@@ -114,6 +130,8 @@ class Gplay():
def _player_eos_cb(self, widget):
logging.debug('end of stream')
+ # Make sure player is stopped after EOS
+ self.player.stop()
def _player_error_cb(self, widget, message, detail):
self.player.stop()
@@ -133,12 +151,12 @@ class Gplay():
self.only_audio = only_audio
self.got_stream_info = True
- def start(self, uri=None):
+ def start(self, file_path=None):
self._want_document = False
- self.playpath = os.path.dirname(uri)
- if not uri:
+ self.playpath = os.path.dirname(file_path)
+ if not file_path:
return False
- self.playlist.append('file://' + urllib.quote(os.path.abspath(uri)))
+ self.playlist.append('file://' + os.path.abspath(file_path))
if not self.player:
# lazy init the player so that videowidget is realized
# and has a valid widget allocation
@@ -149,15 +167,13 @@ class Gplay():
try:
if not self.currentplaying:
- logging.info('Playing: ' + self.playlist[0])
+ logging.info('Playing: %s' % (self.playlist[0]))
self.player.set_uri(self.playlist[0])
self.currentplaying = 0
self.play_toggled()
self.show_all()
- else:
- pass
except:
- pass
+ logging.error('Error playing %s' % (self.playlist[0]))
return False
def play_toggled(self):
@@ -184,7 +200,9 @@ class GstPlayer(gobject.GObject):
self.player = gst.element_factory_make('playbin', 'player')
+ videowidget.realize()
self.videowidget = videowidget
+ self.videowidget_xid = videowidget.window.xid
self._init_video_sink()
bus = self.player.get_bus()
@@ -200,7 +218,7 @@ class GstPlayer(gobject.GObject):
if message.structure is None:
return
if message.structure.get_name() == 'prepare-xwindow-id':
- self.videowidget.set_sink(message.src)
+ self.videowidget.set_sink(message.src, self.videowidget_xid)
message.src.set_property('force-aspect-ratio', True)
def on_message(self, bus, message):
@@ -220,6 +238,8 @@ class GstPlayer(gobject.GObject):
if old == gst.STATE_READY and new == gst.STATE_PAUSED:
self.emit('stream-info',
self.player.props.stream_info_value_array)
+ # else:
+ # logging.debug(message.type)
def _init_video_sink(self):
self.bin = gst.Bin()
@@ -241,7 +261,6 @@ class GstPlayer(gobject.GObject):
caps_string += 'width=%d, height=%d' % (w, h)
else:
caps_string += 'width=480, height=360'
-
caps = gst.Caps(caps_string)
self.filter = gst.element_factory_make('capsfilter', 'filter')
self.bin.add(self.filter)
@@ -269,7 +288,7 @@ class GstPlayer(gobject.GObject):
self.player.set_state(gst.STATE_NULL)
self.playing = False
logging.debug('stopped player')
- return False
+ # return False
def get_state(self, timeout=1):
return self.player.get_state(timeout=timeout)
@@ -294,7 +313,6 @@ class VideoWidget(gtk.DrawingArea):
else:
return True
- def set_sink(self, sink):
- assert self.window.xid
+ def set_sink(self, sink, xid):
self.imagesink = sink
- self.imagesink.set_xwindow_id(self.window.xid)
+ self.imagesink.set_xwindow_id(xid)