Bind volume scale with player volume prop

Now that player API itself is operating on a cubic scale (no value conversion required), the volume slider can be bind to the volume property. Thanks to that, player volume scale will correctly reflect Clapper volume set via external applications e.g. gnome-settings.
This commit is contained in:
Rafał Dzięgiel
2021-02-24 11:09:42 +01:00
parent 775ec8a780
commit 199a8f1931
2 changed files with 20 additions and 44 deletions

41
src/controls.js vendored
View File

@@ -24,7 +24,6 @@ class ClapperControls extends Gtk.Box
can_focus: false,
});
this.currentVolume = 0;
this.currentPosition = 0;
this.currentDuration = 0;
this.isPositionDragging = false;
@@ -409,26 +408,6 @@ class ClapperControls extends Gtk.Box
this.volumeButton.popoverBox.append(this.volumeScale);
}
_updateVolumeButtonIcon(volume)
{
const icon = (volume <= 0)
? 'muted'
: (volume <= 0.3)
? 'low'
: (volume <= 0.7)
? 'medium'
: (volume <= 1)
? 'high'
: 'overamplified';
const iconName = `audio-volume-${icon}-symbolic`;
if(this.volumeButton.icon_name === iconName)
return;
this.volumeButton.set_icon_name(iconName);
debug(`set volume icon: ${icon}`);
}
_setChapterVisible(isVisible)
{
const type = (isVisible) ? 'Show' : 'Hide';
@@ -567,9 +546,6 @@ class ClapperControls extends Gtk.Box
_onVolumeScaleValueChanged(scale)
{
const volume = scale.get_value();
const { player } = this.get_ancestor(Gtk.Grid);
player.set_volume(volume);
/* FIXME: All of below should be placed in 'volume-changed'
* event once we move to message bus API */
@@ -585,7 +561,22 @@ class ClapperControls extends Gtk.Box
scale.remove_css_class(cssClass);
}
this._updateVolumeButtonIcon(volume);
const icon = (volume <= 0)
? 'muted'
: (volume <= 0.3)
? 'low'
: (volume <= 0.7)
? 'medium'
: (volume <= 1)
? 'high'
: 'overamplified';
const iconName = `audio-volume-${icon}-symbolic`;
if(this.volumeButton.icon_name === iconName)
return;
this.volumeButton.icon_name = iconName;
debug(`set volume icon: ${icon}`);
}
_onPositionScaleDragging(scale)

View File

@@ -65,16 +65,16 @@ class ClapperWidget extends Gtk.Grid
const playerWidget = this.player.widget;
this.controls.elapsedButton.scrolledWindow.set_child(this.player.playlistWidget);
this.controls.speedAdjustment.bind_property(
'value', this.player, 'rate', GObject.BindingFlags.BIDIRECTIONAL
);
this.controls.volumeAdjustment.bind_property(
'value', this.player, 'volume', GObject.BindingFlags.BIDIRECTIONAL
);
this.player.connect('position-updated', this._onPlayerPositionUpdated.bind(this));
this.player.connect('duration-changed', this._onPlayerDurationChanged.bind(this));
/* FIXME: re-enable once ported to new GstPlayer API with messages bus */
//this.player.connect('volume-changed', this._onPlayerVolumeChanged.bind(this));
this.overlay.set_child(playerWidget);
this.overlay.add_overlay(this.revealerTop);
this.overlay.add_overlay(this.revealerBottom);
@@ -528,21 +528,6 @@ class ClapperWidget extends Gtk.Grid
this.controls.positionScale.set_value(positionSeconds);
}
_onPlayerVolumeChanged(player)
{
const volume = player.volume;
/* FIXME: This check should not be needed, GstPlayer should not
* emit 'volume-changed' with the same values, but it does. */
if(volume === this.controls.currentVolume)
return;
/* Once above is fixed in GstPlayer, remove this var too */
this.controls.currentVolume = volume;
this.controls._updateVolumeButtonIcon(volume);
}
_onStateNotify(toplevel)
{
const isMaximized = Boolean(