Start loop optionally

This commit is contained in:
Rafostar
2020-09-01 17:49:24 +02:00
parent 326ba66da0
commit fa12f15a9a

View File

@@ -1,6 +1,6 @@
const { GLib, GObject, Gst, GstPlayer } = imports.gi; const { GLib, GObject, Gst, GstPlayer } = imports.gi;
const DEFAULTS = { const GSTPLAYER_DEFAULTS = {
position_update_interval: 1000, position_update_interval: 1000,
seek_accurate: false, seek_accurate: false,
user_agent: 'clapper', user_agent: 'clapper',
@@ -12,7 +12,7 @@ class ClapperPlayer extends GstPlayer.Player
_init(opts) _init(opts)
{ {
opts = opts || {}; opts = opts || {};
Object.assign(opts, DEFAULTS); Object.assign(opts, GSTPLAYER_DEFAULTS);
let gtkglsink = Gst.ElementFactory.make('gtkglsink', null); let gtkglsink = Gst.ElementFactory.make('gtkglsink', null);
let glsinkbin = Gst.ElementFactory.make('glsinkbin', null); let glsinkbin = Gst.ElementFactory.make('glsinkbin', null);
@@ -30,12 +30,13 @@ class ClapperPlayer extends GstPlayer.Player
let config = this.get_config(); let config = this.get_config();
for(let setting of Object.keys(DEFAULTS)) for(let setting of Object.keys(GSTPLAYER_DEFAULTS))
GstPlayer.Player[`config_set_${setting}`](config, opts[setting]); GstPlayer.Player[`config_set_${setting}`](config, opts[setting]);
this.set_config(config); this.set_config(config);
this.loop = GLib.MainLoop.new(null, false); this.loop = GLib.MainLoop.new(null, false);
this.run_loop = opts.run_loop || false;
this.widget = gtkglsink.widget; this.widget = gtkglsink.widget;
this.state = GstPlayer.PlayerState.STOPPED; this.state = GstPlayer.PlayerState.STOPPED;
@@ -58,12 +59,19 @@ class ClapperPlayer extends GstPlayer.Player
this[action](); this[action]();
} }
set_subtitle_font_desc(desc)
{
let pipeline = this.get_pipeline();
pipeline.subtitle_font_desc = desc;
}
_onStateChanged(player, state) _onStateChanged(player, state)
{ {
this.state = state; this.state = state;
if( if(
this.state === GstPlayer.PlayerState.STOPPED this.run_loop
&& this.state === GstPlayer.PlayerState.STOPPED
&& this.loop.is_running() && this.loop.is_running()
) )
this.loop.quit(); this.loop.quit();
@@ -73,7 +81,10 @@ class ClapperPlayer extends GstPlayer.Player
{ {
this.play(); this.play();
if(!this.loop.is_running()) if(
this.run_loop
&& !this.loop.is_running()
)
this.loop.run(); this.loop.run();
} }