Skip to content

Instantly share code, notes, and snippets.

@Barteks2x
Last active August 19, 2021 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Barteks2x/a4e189a36a10c159bb1644ffca21c02a to your computer and use it in GitHub Desktop.
Save Barteks2x/a4e189a36a10c159bb1644ffca21c02a to your computer and use it in GitHub Desktop.
(function() {
'use strict';
const {get, set} = Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'volume');
Object.defineProperty(HTMLMediaElement.prototype, 'volume', {
get () {
const volume = get.call(this);
const newVolume = Math.pow(volume, 1./3.);
console.log('manipulated volume from', volume, 'to ', newVolume, 'on', this);
return newVolume;
},
set (volume) {
// same as https://github.com/pulseaudio/pulseaudio/blob/19adddee31ca34bf4e0db95df01b4ec595f2d267/src/pulse/volume.c#L265-L275
// https://www.robotplanet.dk/audio/audio_gui_design/
const player = document.getElementById('movie_player');
if (player) {
volume = player.getVolume() * 0.01;
}
const newVolume = volume*volume*volume;
console.log('manipulated volume to ', newVolume, ' from', volume, 'on', this);
return set.call(this, newVolume);
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment