mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-29 23:32:04 +02:00
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:
41
src/controls.js
vendored
41
src/controls.js
vendored
@@ -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)
|
||||
|
@@ -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(
|
||||
|
Reference in New Issue
Block a user