Tuesday, January 4, 2011

New Quidget: MediaPlayerBox adds video to your app in a few lines

I've created a new quickly-widget to make it dead simple to add a video or sound file to a Quickly application. All you need to do is create a MediaPlayerBox, add it to your app, set the uri property to tell it what file to play, and call "play()". 5 lines to playing a video:
        self.player = MediaPlayerBox(True)
self.player.show()
self.ui.vbox1.pack_start(self.player)
self.player.uri = file_to_play
self.player.play()
By passing in True when I created the MediaPlayerBox, that told it to display controls. You can also control whether controls are displayed by setting the controls_visible property:
        self.player.controls_visible = True

It's got other functions that you would expect:
        self.player.pause()
self.player.stop()

And other useful properties too. For example, you can get the duration of the current media file, and you can get and set the current position. So you could seek to halfway through the media file like this:
        dur = self.player.duration
self.player.position = dur/2

MediaPlayerBox is really just a thin wrapper around the gstreamer's playbin, so you still have all the power of gstreamer if you end up needing to go there. You can just use the playbin property and go to town if it comes to it.

But MediaPlayerBox is focused on simplicity, just getting a video or song playing n your app esasily.

MediaPlayerBox is currently in a branch, so you can grab it and try it out.

3 comments:

  1. Excellent, this is something i needed during the last UDS. When attending remotely, you have to fight with tons of apps. A browser (for blueprints, the schedule, the icecast links, the video feeds for the plenaries, the miro channel), with gwibber, totem, gobby, etc. So I wanted to merge all those into a quickly app. I investigated the various bits needed but UDS ended before i even got a chance to start coding :P

    ReplyDelete
  2. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
    html5 audio player

    ReplyDelete