简体   繁体   中英

How to play multiple audio track video in HTML5 <video>?

I have an MKV file with multiple audio tracks, with a languages each. I want to add a button to changes the language. Can someone help me do it ?

HTML:

<video autoplay id="videoid" controls controlsList="nodownload" disablePictureInPicture poster="<?php echo base_url();?>assets/user/images/loading.jpg">
                            <source src="<?php echo base_url(); ?>uploads/images_or_videos/<?php echo $content->image_or_video; ?>" type="video/webm">
                        </video>

Javascript:

$(document).ready(function(){
   var aud = document.getElementById("videoid");
    aud.onplaying  = function() {
    alert(aud.audioTracks.length);   
}
});
var video = document.getElementById("video");

// mute all
for (var i = 0; i < video.audioTracks.length; i += 1) {
  video.audioTracks[i].enabled = false;
}

// show languages and labels
for (var i = 0; i < video.audioTracks.length; i += 1) {
  console.log(video.audioTracks[i].language)
  console.log(video.audioTracks[i].label)
}

// enable one
video.audioTracks[2].enabled = true;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM