import pygst
pygst.require("0.10")
import gst
import sys
import gobject

class Player:
    def __init__(self, filename):
        self.filename = filename
        self.player = gst.element_factory_make("playbin2", "player")
	self.ass = gst.element_factory_make("autoaudiosink", "autoaudiosink")
        self.player.set_property("uri", filename)
	self.player.set_property("audio-sink", self.ass)
        self.player.connect("about-to-finish", self.on_about_to_finish)

    def run(self):
        self.player.set_state(gst.STATE_PLAYING)
        loop = gobject.MainLoop()
        loop.run()

    def on_about_to_finish(self, player):
        print 'about-to-finish'
        player.set_property("uri", self.filename)

if __name__ == "__main__":
    gobject.threads_init()
    player = Player("file:///usr/share/gnome-games/sounds/gnometris.ogg")
    player.run()
