Add seeking on slider drop and make it default behaviour

Seeking during slider drag is very CPU and HDD intensive task. We are requesting the player to keep seeking in VERY short amounts of time. This can be performed more effectively by doing a single seek after slider drop. Since this is a different behaviour then usually in media players, I am making this optional (enabled by default).
This commit is contained in:
Rafostar
2020-09-02 18:31:22 +02:00
parent fd2ad7e596
commit 70ec6311c0
2 changed files with 51 additions and 5 deletions

View File

@@ -1,7 +1,12 @@
const { GObject, Gtk } = imports.gi; const { GObject, Gtk } = imports.gi;
var Controls = GObject.registerClass( var Controls = GObject.registerClass({
class ClapperControls extends Gtk.HBox Signals: {
'position-seeking-changed': {
param_types: [GObject.TYPE_BOOLEAN]
},
}
}, class ClapperControls extends Gtk.HBox
{ {
_init() _init()
{ {
@@ -27,6 +32,13 @@ class ClapperControls extends Gtk.HBox
value_pos: Gtk.PositionType.LEFT, value_pos: Gtk.PositionType.LEFT,
draw_value: false draw_value: false
}); });
this.positionScale.connect(
'button-press-event', this._onPositionScaleButtonPressEvent.bind(this)
);
this.positionScale.connect(
'button-release-event', this._onPositionScaleButtonReleaseEvent.bind(this)
);
this.positionAdjustment = this.positionScale.get_adjustment(); this.positionAdjustment = this.positionScale.get_adjustment();
this.pack_start(this.positionScale, true, true, 0); this.pack_start(this.positionScale, true, true, 0);
@@ -108,4 +120,16 @@ class ClapperControls extends Gtk.HBox
} }
} }
} }
_onPositionScaleButtonPressEvent()
{
this.isPositionSeeking = true;
this.emit('position-seeking-changed', this.isPositionSeeking);
}
_onPositionScaleButtonReleaseEvent()
{
this.isPositionSeeking = false;
this.emit('position-seeking-changed', this.isPositionSeeking);
}
}); });

View File

@@ -4,10 +4,15 @@ const { Controls } = imports.clapper_src.controls;
var Interface = GObject.registerClass( var Interface = GObject.registerClass(
class ClapperInterface extends Gtk.Grid class ClapperInterface extends Gtk.Grid
{ {
_init() _init(opts)
{ {
super._init(); super._init();
let defaults = {
seekOnDrop: true
};
Object.assign(this, defaults, opts);
this.lastVolumeValue = null; this.lastVolumeValue = null;
this.lastPositionValue = 0; this.lastPositionValue = 0;
@@ -34,6 +39,9 @@ class ClapperInterface extends Gtk.Grid
this.controls.volumeButton.connect( this.controls.volumeButton.connect(
'value-changed', this._onControlsVolumeChanged.bind(this) 'value-changed', this._onControlsVolumeChanged.bind(this)
); );
this.controls.connect(
'position-seeking-changed', this._onPositionSeekingChanged.bind(this)
);
this.attach(this._player.widget, 0, 0, 1, 1); this.attach(this._player.widget, 0, 0, 1, 1);
} }
@@ -72,6 +80,9 @@ class ClapperInterface extends Gtk.Grid
_onPlayerPositionUpdated(player, position) _onPlayerPositionUpdated(player, position)
{ {
if(this.controls.isPositionSeeking)
return;
let positionSeconds = position / 1000000000; let positionSeconds = position / 1000000000;
let positionFloor = Math.floor(positionSeconds); let positionFloor = Math.floor(positionSeconds);
@@ -92,14 +103,25 @@ class ClapperInterface extends Gtk.Grid
this.controls.volumeButton.set_value(volume); this.controls.volumeButton.set_value(volume);
} }
_onPositionSeekingChanged(self, isPositionSeeking)
{
if(isPositionSeeking || !this.seekOnDrop)
return;
this._onControlsPositionChanged(this.controls.positionScale);
}
_onControlsTogglePlayClicked() _onControlsTogglePlayClicked()
{ {
this._player.toggle_play(); this._player.toggle_play();
} }
_onControlsPositionChanged(range) _onControlsPositionChanged(positionScale)
{ {
let position = Math.floor(range.get_value()); if(this.seekOnDrop && this.controls.isPositionSeeking)
return;
let position = Math.floor(positionScale.get_value());
if(position === this.lastPositionValue) if(position === this.lastPositionValue)
return; return;