From 4d1166a9520ec05ebfbd95bd65adadfa485a8271 Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Sat, 29 Aug 2020 15:48:38 +0200 Subject: [PATCH] Initial version upload --- GtkPlayer.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 GtkPlayer.js diff --git a/GtkPlayer.js b/GtkPlayer.js new file mode 100644 index 00000000..625370f5 --- /dev/null +++ b/GtkPlayer.js @@ -0,0 +1,53 @@ +const { GLib, GObject, Gst, GstPlayer } = imports.gi; + +var GtkPlayer = GObject.registerClass( +class GtkPlayer extends GstPlayer.Player +{ + _init() + { + let gtkglsink = Gst.ElementFactory.make('gtkglsink', null); + let glsinkbin = Gst.ElementFactory.make('glsinkbin', null); + glsinkbin.sink = gtkglsink; + + let dispatcher = new GstPlayer.PlayerGMainContextSignalDispatcher(); + let renderer = new GstPlayer.PlayerVideoOverlayVideoRenderer({ + video_sink: glsinkbin + }); + + super._init({ + signal_dispatcher: dispatcher, + video_renderer: renderer + }); + + this.loop = GLib.MainLoop.new(null, false); + this.widget = gtkglsink.widget; + this.state = GstPlayer.PlayerState.STOPPED; + + this.connect('state_changed', this._onStateChanged.bind(this)); + this.connect('uri_loaded', this._onUriLoaded.bind(this)); + this.widget.connect('destroy', this._onWidgetDestroy.bind(this)); + } + + _onStateChanged(player, state) + { + this.state = state; + + if( + this.state === GstPlayer.PlayerState.STOPPED + && this.loop.is_running() + ) + this.loop.quit(); + } + + _onUriLoaded() + { + this.play(); + this.loop.run(); + } + + _onWidgetDestroy() + { + if(this.state !== GstPlayer.PlayerState.STOPPED) + this.stop(); + } +});