Hello all,

Here is some sample code to play any type of file supported by
gstreamer's playbin. I think it is a good substitute for
pyclutter/examples/videosink.py. Lots of code has been omitted that let
you connect gstreamer's bus to a callback so this is simple.

 

# Simple video player that outputs to a clutter texture

# For more funky control of the gst player like bus messages

# seeking and pausing, please see the gstreamer playbin document

# This has been tested with clutter trunk and not the stable branch

import gst

from clutter import cluttergst

import clutter

import gobject

import sys

 

class GstPlayer:

    def __init__(self, stage, vfile):

        self.stage = stage

 

        self.video_texture = cluttergst.VideoTexture()

        self.pipeline = gst.Pipeline("mypipe")

        self.playbin = self.video_texture.get_playbin()

 

        # Setup uri and sinks

        self.set_location(vfile)

        self.pipeline.add(self.playbin)

 

        # Finally add the video to the stage

        self.stage.add(self.video_texture)

 

        # play it

        self.pipeline.set_state(gst.STATE_PLAYING)

 

    def set_location(self, location):

        if not gst.uri_is_valid(location):

            location = "file://" + location

 

        self.playbin.set_property('uri', location)

 

def main():

    stage = clutter.stage_get_default()

    stage.set_size(320,240)

    stage.set_color(clutter.color_parse('DarkSlateGrey'))

    stage.connect('key-press-event', clutter.main_quit)

 

    player = GstPlayer(stage, sys.argv[1])

    stage.show_all()

 

    loop = gobject.MainLoop()

    try:

        #loop.run()    # This runs the gobject main loop via python
bindings

        clutter.main() # This has the side effect of making telepathy
unusable

    except KeyboardInterrupt:

        print 'interrupted'

 

    return 0

 

# the first command line argument is the name of the file or a URI

if __name__ == '__main__':

    main()

 

 

Reply via email to