Add playback speed control

Adjustable playback speed control in the form of a slider with a range from 0.01x to 2x.

Closes #33
This commit is contained in:
Rafostar
2021-01-19 16:20:22 +01:00
parent 3ba21d42ec
commit 994491d687
3 changed files with 38 additions and 7 deletions

View File

@@ -40,13 +40,7 @@ class ClapperControls extends Gtk.Box
this.chapterHideId = null;
this._addTogglePlayButton();
const elapsedRevealer = new Revealers.ButtonsRevealer('SLIDE_RIGHT');
this.elapsedButton = this.addElapsedPopoverButton('00:00/00:00', elapsedRevealer);
elapsedRevealer.set_reveal_child(true);
this.revealersArr.push(elapsedRevealer);
this.append(elapsedRevealer);
this._addElapsedButton();
this._addPositionScale();
const revealTracksButton = new Buttons.IconToggleButton(
@@ -318,6 +312,35 @@ class ClapperControls extends Gtk.Box
this.addButton(this.togglePlayButton);
}
_addElapsedButton()
{
const elapsedRevealer = new Revealers.ButtonsRevealer('SLIDE_RIGHT');
this.elapsedButton = this.addElapsedPopoverButton('00:00/00:00', elapsedRevealer);
elapsedRevealer.set_reveal_child(true);
this.revealersArr.push(elapsedRevealer);
const speedScale = new Gtk.Scale({
orientation: Gtk.Orientation.HORIZONTAL,
value_pos: Gtk.PositionType.BOTTOM,
draw_value: false,
round_digits: 2,
hexpand: true,
valign: Gtk.Align.CENTER,
});
this.speedAdjustment = speedScale.get_adjustment();
this.speedAdjustment.set_lower(0.01);
this.speedAdjustment.set_upper(2);
this.speedAdjustment.set_value(1);
speedScale.add_mark(0.25, Gtk.PositionType.BOTTOM, '0.25x');
speedScale.add_mark(1, Gtk.PositionType.BOTTOM, 'normal');
speedScale.add_mark(2, Gtk.PositionType.BOTTOM, '2x');
this.elapsedButton.popoverBox.append(speedScale);
this.append(elapsedRevealer);
}
_addPositionScale()
{
this.positionScale = new Gtk.Scale({

View File

@@ -78,6 +78,11 @@ class ClapperPlayer extends PlayerBase
set_uri(uri)
{
/* FIXME: Player does not notify about
* rate change after file load */
if(this.rate !== 1)
this.set_rate(1);
if(Gst.Uri.get_protocol(uri) !== 'file')
return super.set_uri(uri);

View File

@@ -46,6 +46,9 @@ class ClapperWidget extends Gtk.Grid
this.player = new Player();
this.controls.elapsedButton.scrolledWindow.set_child(this.player.playlistWidget);
this.controls.speedAdjustment.bind_property(
'value', this.player, 'rate', GObject.BindingFlags.BIDIRECTIONAL
);
this.player.connect('position-updated', this._onPlayerPositionUpdated.bind(this));
this.player.connect('duration-changed', this._onPlayerDurationChanged.bind(this));