Skip to content

Instantly share code, notes, and snippets.

@bojidaryovchev
Created March 31, 2023 23:26
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 bojidaryovchev/8b48adeeea84a59cc21b0bc5fa241b37 to your computer and use it in GitHub Desktop.
Save bojidaryovchev/8b48adeeea84a59cc21b0bc5fa241b37 to your computer and use it in GitHub Desktop.
function amplifyMedia(mediaElem, multiplier) {
var context = new (window.AudioContext || window.webkitAudioContext),
result = {
context: context,
source: context.createMediaElementSource(mediaElem),
gain: context.createGain(),
media: mediaElem,
amplify: function(multiplier) { result.gain.gain.value = multiplier; },
getAmpLevel: function() { return result.gain.gain.value; }
};
result.source.connect(result.gain);
result.gain.connect(context.destination);
result.amplify(multiplier);
return result;
}
let [video] = document.getElementsByTagName('video');
let multiplier = 4;
amplifyMedia(video, multiplier);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment