Development Team/Almanac/GStreamer: Difference between revisions

No edit summary
Newacct (talk | contribs)
mNo edit summary
 
(10 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{Sugar Almanac}}
{{Almanac}}


=== Where can I get additional resources and sample code on using the camera? ===
=== Where can I get additional resources and sample code on using the camera? ===
Line 50: Line 50:
def setFile(self, path):
def setFile(self, path):
uri = "file://" + str( path )
uri = "file://" + str( path )
if (self.player.get_property('uri') == uri):
if self.player.get_property('uri') == uri:
self.seek(gst.SECOND*0)
self.seek(gst.SECOND*0)
return
return
Line 57: Line 57:
self.player.set_property('uri', uri)
self.player.set_property('uri', uri)
ext = uri[len(uri)-3:]
ext = uri[len(uri)-3:]
if (ext == "jpg"):
if ext == "jpg":
self.pause()
self.pause()
else:
else:
Line 119: Line 119:


def set_sink(self, sink):
def set_sink(self, sink):
if (self.imagesink != None):
if self.imagesink != None:
assert self.window.xid
assert self.window.xid
self.imagesink = None
self.imagesink = None
Line 143: Line 143:
self.gplayWin.resize( 300, 400 )
self.gplayWin.resize( 300, 400 )
self.gplayWin.show_all( )
self.gplayWin.show_all( )
</pre>
Alternatively, you could embed your video into a gtk.DrawingArea:
<pre>
class VideoWidget(gtk.DrawingArea):
    def __init__(self):
        gtk.DrawingArea.__init__(self)
        self.set_events(gtk.gdk.POINTER_MOTION_MASK |
        gtk.gdk.POINTER_MOTION_HINT_MASK |
        gtk.gdk.EXPOSURE_MASK |
        gtk.gdk.KEY_PRESS_MASK |
        gtk.gdk.KEY_RELEASE_MASK)
        self.imagesink = None
        self.unset_flags(gtk.DOUBLE_BUFFERED)
        self.set_flags(gtk.APP_PAINTABLE)
    def do_expose_event(self, event):
        if self.imagesink:
            self.imagesink.expose()
            return False
        else:
            return True
    def set_sink(self, sink):
        assert self.window.xid
        self.imagesink = sink
        self.imagesink.set_xwindow_id(self.window.xid)
</pre>
</pre>


=== How can I add play/pause buttons and a scrubber to my audio or video? ===
=== How can I add play/pause buttons and a scrubber to my audio or video? ===
The widget below is pre-configured to work with the gplay class above.  This widget takes two gtk.Images in its constructor.
<pre>
<pre>
import gtk
import gtk
Line 208: Line 240:


def removeCallbacks( self ):
def removeCallbacks( self ):
if (self.UPDATE_SCALE_ID != 0):
if self.UPDATE_SCALE_ID != 0:
gobject.source_remove(self.UPDATE_SCALE_ID)
gobject.source_remove(self.UPDATE_SCALE_ID)
self.UPDATE_SCALE_ID = 0
self.UPDATE_SCALE_ID = 0
if (self.CHANGED_ID != 0):
if self.CHANGED_ID != 0:
gobject.source_remove(self.CHANGED_ID)
gobject.source_remove(self.CHANGED_ID)
self.CHANGED_ID = 0
self.CHANGED_ID = 0
Line 234: Line 266:
def play_toggled(self):
def play_toggled(self):
self.p_position, self.p_duration = self._gplay.queryPosition()
self.p_position, self.p_duration = self._gplay.queryPosition()
if (self.p_position == self.p_duration):
if self.p_position == self.p_duration:
self._gplay.seek(0)
self._gplay.seek(0)
self._gplay.pause()
self._gplay.pause()
Line 299: Line 331:
if self.p_position != gst.CLOCK_TIME_NONE:
if self.p_position != gst.CLOCK_TIME_NONE:
value = self.p_position * 100.0 / self.p_duration
value = self.p_position * 100.0 / self.p_duration
if (value > 99):
if value > 99:
value = 99
value = 99
elif (value < 0):
elif value < 0:
value = 0
value = 0


self.adjustment.set_value(value)
self.adjustment.set_value(value)


if self._gplay.is_playing() and (self.p_position == self.p_duration):
if self._gplay.is_playing() and self.p_position == self.p_duration:
self._gplay.pause()
self._gplay.pause()
self.set_button_play()
self.set_button_play()