#!/bin/env python3
try:
  from ctypes import cdll
  XLib = cdll.LoadLibrary("libX11.so.6")
  XLib.XInitThreads()
except OSError:
  print("Didn't initialize X11 threading " +
        "(libX11.so.6 not found, or not running X11)")
  pass

from gi import require_version
require_version("Gst", "1.0")
require_version("Gtk", "3.0")
from gi.repository import Gst, Gtk

Gst.init(None)
Gtk.init(None)

sink = Gst.ElementFactory.make("glsinkbin")
gtksink = Gst.ElementFactory.make("gtkglsink")
sink.set_property("sink", gtksink)
playbin = Gst.ElementFactory.make("playbin")
playbin.set_property("video-sink", sink)
playbin.set_property("uri", "http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4")

window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
window.connect("delete-event", Gtk.main_quit)
window.set_default_size(640, 480)
show_headerbar = True # ENABLES/DISABLES HEADERBAR
if show_headerbar:
  window.set_titlebar(Gtk.HeaderBar())
  window.get_titlebar().set_show_close_button(True)
widget = gtksink.get_property("widget")
box = Gtk.Box()
box.pack_start(widget, True, True, 0)
window.add(box)

window.show_all()
playbin.set_state(Gst.State.PLAYING)

Gtk.main()
