-
-
Save amundo/c9f329da840680defb5b775a390cc19c to your computer and use it in GitHub Desktop.
Function that can be used to amplify the volume of a media element (<audio> or <video>).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>My Test Video</title> | |
</head> | |
<body> | |
<video id="myVideo" controls src="video.mp4"></video> | |
<script src="createAmplifier.js"></script> | |
<script type="text/JavaScript"> | |
// Make my video twice as loud as normal. | |
createAmplifier(document.getElementById('myVideo'), 2); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment