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

test11.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import sys
  2. import os
  3. if sys.version_info[0] < 3:
  4. import Tkinter as tkinter
  5. else:
  6. import tkinter
  7. import gi
  8. gi.require_version('Gst', '1.0')
  9. from gi.repository import Gst, GObject
  10. # Needed for set_window_handle():
  11. gi.require_version('GstVideo', '1.0')
  12. from gi.repository import GstVideo
  13. def set_frame_handle(bus, message, frame_id):
  14. if not message.get_structure() is None:
  15. if message.get_structure().get_name() == 'prepare-window-handle':
  16. display_frame = message.src
  17. display_frame.set_property('force-aspect-ratio', True)
  18. display_frame.set_window_handle(frame_id)
  19. NUMBER_OF_FRAMES = 8 # with more frames than arguments, videos are repeated
  20. relative_height = 1 / float(NUMBER_OF_FRAMES)
  21. # Only argument number checked, not validity.
  22. number_of_file_names_given = len(sys.argv) - 1
  23. if number_of_file_names_given < 1:
  24. print('Give at least one video file name.')
  25. sys.exit()
  26. if number_of_file_names_given < NUMBER_OF_FRAMES:
  27. print('Up to', NUMBER_OF_FRAMES, 'video file names can be given.')
  28. file_names = list()
  29. for index in range(number_of_file_names_given):
  30. file_names.append(sys.argv[index + 1])
  31. window = tkinter.Tk()
  32. window.title("Multiple videos in a column using Tk and GStreamer 1.0")
  33. window.geometry('480x960')
  34. Gst.init(None)
  35. GObject.threads_init()
  36. for number in range(NUMBER_OF_FRAMES):
  37. display_frame = tkinter.Frame(window, bg='')
  38. relative_y = number * relative_height
  39. display_frame.place(relx = 0, rely = relative_y,
  40. anchor = tkinter.NW, relwidth = 1, relheight = relative_height)
  41. frame_id = display_frame.winfo_id()
  42. player = Gst.ElementFactory.make('playbin', None)
  43. fullname = os.path.abspath(file_names[number % len(file_names)])
  44. player.set_property('uri', fullname)
  45. player.set_state(Gst.State.PLAYING)
  46. bus = player.get_bus()
  47. bus.enable_sync_message_emission()
  48. bus.connect('sync-message::element', set_frame_handle, frame_id)
  49. window.mainloop()