Enigma2 plugin to to play various online streams (mostly Latvian).

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import sys, os
  2. import gi
  3. gi.require_version('Gst', '1.0')
  4. gi.require_version('Gtk', '3.0')
  5. gi.require_version('GdkX11', '3.0')
  6. gi.require_version('GstVideo', '1.0')
  7. from gi.repository import Gst, GObject, Gtk
  8. # Needed for window.get_xid(), xvimagesink.set_window_handle(), respectively:
  9. from gi.repository import GdkX11, GstVideo
  10. class GTK_Main(object):
  11. def __init__(self):
  12. window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
  13. window.set_title("Video-Player")
  14. window.set_default_size(500, 400)
  15. window.connect("destroy", Gtk.main_quit, "WM destroy")
  16. vbox = Gtk.VBox()
  17. window.add(vbox)
  18. hbox = Gtk.HBox()
  19. vbox.pack_start(hbox, False, False, 0)
  20. self.entry = Gtk.Entry()
  21. hbox.add(self.entry)
  22. self.button = Gtk.Button("Start")
  23. hbox.pack_start(self.button, False, False, 0)
  24. self.button.connect("clicked", self.start_stop)
  25. self.movie_window = Gtk.DrawingArea()
  26. vbox.add(self.movie_window)
  27. window.show_all()
  28. self.player = Gst.ElementFactory.make("playbin", "player")
  29. bus = self.player.get_bus()
  30. bus.add_signal_watch()
  31. bus.enable_sync_message_emission()
  32. bus.connect("message", self.on_message)
  33. bus.connect("sync-message::element", self.on_sync_message)
  34. def start_stop(self, w):
  35. if self.button.get_label() == "Start":
  36. filepath = self.entry.get_text().strip()
  37. if os.path.isfile(filepath):
  38. filepath = os.path.realpath(filepath)
  39. self.button.set_label("Stop")
  40. self.player.set_property("uri", filepath)
  41. self.player.set_state(Gst.State.PLAYING)
  42. else:
  43. self.player.set_state(Gst.State.NULL)
  44. self.button.set_label("Start")
  45. def on_message(self, bus, message):
  46. t = message.type
  47. if t == Gst.MessageType.EOS:
  48. self.player.set_state(Gst.State.NULL)
  49. self.button.set_label("Start")
  50. elif t == Gst.MessageType.ERROR:
  51. self.player.set_state(Gst.State.NULL)
  52. err, debug = message.parse_error()
  53. print "Error: %s" % err, debug
  54. self.button.set_label("Start")
  55. def on_sync_message(self, bus, message):
  56. if message.get_structure().get_name() == 'prepare-window-handle':
  57. imagesink = message.src
  58. imagesink.set_property("force-aspect-ratio", True)
  59. imagesink.set_window_handle(self.movie_window.get_property('window').get_xid())
  60. GObject.threads_init()
  61. Gst.init(None)
  62. GTK_Main()
  63. Gtk.main()