i have videos with multiple audio tracks. i want to play the video and want change audio tracks from video. Is there any way to make this in html or there is html supported player for this?
If you want to grab the audio track from an html5 video you can get the video element by id and then use the .audioTracks
array and pass in the index of the track you with to access.
var video = document.getElementById("video");
for (var i = 0; i < video.audioTracks.length; i += 1) {
video.audioTracks[i].enabled = false;
}
MDN Docs: HTMLMediaElement.audioTracks
Furthermore, if you are looking to manipulate the audio, William provides a good answer (https://stackoverflow.com/a/15286719/6931862) using AudioContext
Below is the response provided in the link above, but with some edits to account for the updated adoption for AudioContext
(used to be webkitAudioContext
)
<script>
var video = document.createElement("video");
video.setAttribute("src", "ourMovie.mov");
video.controls = true;
video.autoplay = true;
document.body.appendChild(video);
var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext(); // get access to audio context
var gainNode = audioCtx.createGain();
gainNode.gain.value = 1; // Change Gain Value to test
filter = audioCtx.createBiquadFilter();
filter.type = 2; // Change Filter type to test
filter.frequency.value = 5040; // Change frequency to test
// Wait for window.onload to fire. See crbug.com/112368
window.addEventListener('load', function(e) {
// Our <video> element will be the audio source.
var source = audioCtx.createMediaElementSource(video);
source.connect(gainNode);
gainNode.connect(filter);
filter.connect(audioCtx.destination);
}, false);
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With