Listing 2. Clutter-Based Video Player

import clutter
import gst
from clutter import cluttergst

class HelloWorld:
    def __init__ (self):
        # Create stage and set its properties.
        self.stage = clutter.Stage()
        self.stage.set_color(clutter.color_parse('Black'))
        self.stage.set_size(500, 400)
        self.stage.set_title('Clutter Basic Video Player')

        # Create signal for handling mouse clicks.
        self.stage.connect('button-press-event', self.mouseClick)

        # Create play button shape.
        self.playBtn = clutter.Rectangle()
        self.playBtn.set_color(clutter.Color(66, 99, 150, 0x99))
        self.playBtn.set_size(50, 30)
        self.playBtn.set_position(118, 34)
        self.stage.add(self.playBtn)

        # Create play button text
        # and overlay the rectangle.
        playTxt = clutter.Label()
        playTxt.set_text("Play")
        playTxt.set_color(clutter.color_parse('Black'))
        playTxt.set_position(130, 40)
        self.stage.add(playTxt)

                # Same for stop button.
        self.stopBtn = clutter.Rectangle()
        self.stopBtn.set_color(clutter.Color(66, 99, 150, 0x99))
        self.stopBtn.set_size(50, 30)
        self.stopBtn.set_position(218, 34)
        self.stage.add(self.stopBtn)

        StopTxt = clutter.Label()
        StopTxt.set_text("Pause")
        StopTxt.set_color(clutter.color_parse('Black'))
        StopTxt.set_position(225, 40)
        self.stage.add(StopTxt)

        # Create video texture.
        video_tex = cluttergst.VideoTexture()

        self.pipeline = gst.Pipeline("mypipe")
        playbin = video_tex.get_playbin()

        # Specify video file to play.
        movfile = "file:///home/user/Videos/Video.mov"
        playbin.set_property('uri', movfile)

        # Add to playbin to the pipeline.
        self.pipeline.add(playbin)

        # Set position and start playing the video.
        video_tex.set_position(90,100)
        self.stage.add(video_tex)
        self.pipeline.set_state(gst.STATE_PLAYING)

        self.stage.show_all()
        clutter.main()

    def mouseClick (self, stage, event):
        # Mouse click function, called when the moused
        # is clicked *anywhere* on the stage, we check
        # the mouse coordinates manually to see if the
        # click occurred inside a button.

        # Check for left mouse button.
        if event.button == 1:

            # Check to see if stop button was pressed.
            if event.x > 218 and event.x < 268 and \
               event.y > 34  and event.y < 64:

                self.stopBtn.set_color(clutter.Color(33,50,150,0x89))
                self.playBtn.set_color(clutter.Color(66,99,150,0x99))
                    self.stopBtn.set_size(49, 29)
                    self.playBtn.set_size(50, 30)
                self.pipeline.set_state(gst.STATE_PAUSED)

            # Check to see if the play button was pressed.
            if event.x > 118 and event.x < 168 and \
               event.y > 34  and event.y < 64:

                self.playBtn.set_color(clutter.Color(33,50,150,0x89))
                self.stopBtn.set_color(clutter.Color(66,99,150,0x99))
                self.playBtn.set_size(49, 29)
                self.stopBtn.set_size(50, 30)
                self.pipeline.set_state(gst.STATE_PLAYING)


# Run program.
main = HelloWorld()

