[Glade-devel] embedding video in drawing area

Hi Everyone this is my first post here.

I downloaded the complete source files to build Trisquel Linux(based off 
Ubuntu). I found many glade/ui files in the projects and have many 
sample applications to study but unfortunately I could not find an 
example of embedding video, even with totem.

I also downloaded this pygtk book:

On page 89 it describes how to embed video with gstreamer. The samples 
worked well for me but I am having trouble moving the concepts from 
hand-coded GTK to glade.  Are there any examples of this sort of thing 
with glade?

This is asking too much but could someone possibly explain how to turn a 
glade drawing area into a video widget? I understand that gstreamer is 
emitting signals to synchronize the drawing widget but I don't 
understand how the video actually gets drawn or is wired in to the 

Here is the code from the book that I am struggling with. Thanks for 
reading-Patrick :

import pygst
import gst
import pygtk
import gtk
import sys

class Main(object):
     def __init__(self):

         # Create the GUI
         self.win = gtk.Window()
         self.win.set_title("Play Video Example")
         self.win.connect("delete_event", lambda w,e: gtk.main_quit())

         vbox = gtk.VBox(False, 0)
         hbox = gtk.HBox(False, 0)

         self.load_file = gtk.FileChooserButton("Choose Audio File")
         self.play_button = gtk.Button("Play", gtk.STOCK_MEDIA_PLAY)
         self.pause_button = gtk.Button("Pause", gtk.STOCK_MEDIA_PAUSE)
         self.stop_button = gtk.Button("Stop", gtk.STOCK_MEDIA_STOP)

         self.videowidget = gtk.DrawingArea()
         self.videowidget.set_size_request(400, 250)

         self.load_file.connect("selection-changed", self.on_file_selected)
         self.play_button.connect("clicked", self.on_play_clicked)
         self.pause_button.connect("clicked", self.on_pause_clicked)
         self.stop_button.connect("clicked", self.on_stop_clicked)

         hbox.pack_start(self.play_button, False, True, 0)
         hbox.pack_start(self.pause_button, False, True, 0)
         hbox.pack_start(self.stop_button, False, True, 0)

         vbox.pack_start(self.load_file, False, True, 0)
         vbox.pack_start(self.videowidget, True, True, 0) # You want to 
expand the video widget or else you cannot see it
         vbox.pack_start(hbox, False, True, 0)


         # Setup GStreamer
         self.player = gst.element_factory_make("playbin", 

         bus = self.player.get_bus()

         #used to get messages that gstreamer emits
         bus.connect("message", self.on_message)

         #used for connecting video to your application
         bus.connect("sync-message::element", self.on_sync_message)

     def on_file_selected(self, widget):
         print "Selected: ", self.load_file.get_filename()
         self.multimedia_file = self.load_file.get_filename()

     def on_play_clicked(self, widget):
         print "play"
         self.player.set_property('uri', "file://" + self.multimedia_file)

     def on_pause_clicked(self, widget):
         print "pause"

     def on_stop_clicked(self, widget):
         print "stop"

     def on_message(self, bus, message):
         if message.type == gst.MESSAGE_EOS: # End of Stream
         elif message.type == gst.MESSAGE_ERROR:
             (err, debug) = message.parse_error()
             print "Error: %s" % err, debug

     def on_sync_message(self, bus, message):
         if message.structure is None:
             return False
         if message.structure.get_name() == "prepare-xwindow-id":
             if sys.platform == "win32":
                 win_id = self.videowidget.window.handle
                 win_id = self.videowidget.window.xid
             assert win_id
             imagesink = message.src
             imagesink.set_property("force-aspect-ratio", True)

if __name__ == "__main__":

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]