如何在HTML5 <video>中播放多个音轨视频?

时间:2019-03-01 08:07:38

标签: javascript php jquery html

我有一个MKV文件,其中包含多个音轨,每种音轨都有一种语言。我想添加一个按钮来更改语言。有人可以帮我吗?

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);   
}
});

1 个答案:

答案 0 :(得分:0)

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;