Created
July 27, 2023 09:01
-
-
Save meta-ks/d09d3d44959fdf4561f12f22edc7065c to your computer and use it in GitHub Desktop.
audio booster for youtube and all
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 to adjust the volume of a video element | |
function adjustVideoVolume(videoElement, volume) { | |
// Create an audio context | |
const audioCtx = new (window.AudioContext || window.webkitAudioContext)(); | |
// Create a media element source from the video element | |
const source = audioCtx.createMediaElementSource(videoElement); | |
// Create a gain node to control the volume | |
const gainNode = audioCtx.createGain(); | |
// Set the desired volume level | |
gainNode.gain.value = volume; | |
// Connect the video's audio to the gain node | |
source.connect(gainNode); | |
// Connect the gain node to the audio context's destination (output) | |
gainNode.connect(audioCtx.destination); | |
} | |
// Usage example: | |
var videoElement = document.querySelector("video"); | |
// Adjust this value to set the desired volume level (2 for double volume) | |
adjustVideoVolume(videoElement, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment