mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-31 00:11:59 +02:00
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:
28
clapper_src/controls.js
vendored
28
clapper_src/controls.js
vendored
@@ -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);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
@@ -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;
|
||||||
|
Reference in New Issue
Block a user