# https://bugzilla.gnome.org/show_bug.cgi?id=656641

import gobject
import gst

gobject.threads_init()
mainloop = gobject.MainLoop()

gbin = gst.Bin()
ofa = ["ofa", "fakesink"]
ofa = map(gst.element_factory_make, ofa)
map(gbin.add, ofa)
gst.element_link_many(*ofa)

gbin.add_pad(gst.GhostPad('sink', ofa[0].get_pad('sink')))

playbin = gst.element_factory_make("playbin")
playbin.set_property('audio-sink', gbin)
playbin.set_property('uri', 'file:///home/user/Desktop/x.mp3')

bus = playbin.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
def bus_message(bus, message):
    if message.type == gst.MESSAGE_EOS:
        playbin.set_state(gst.STATE_NULL)
        playbin.get_state()
        mainloop.quit()

bus.connect("message", bus_message)

playbin.set_state(gst.STATE_PLAYING)

mainloop.run()

print "OK"
