在< video>上播放多个音轨;元件? [英] Playing multiple audio tracks on <video> element?
问题描述
我正在尝试为常规HLS视频流创建一个可访问的< video>
元素。但是,我注意到,没有跨浏览器的方法可以指定多个音轨并在它们之间进行高效切换,就像您可以使用隐藏字幕一样。
I'm trying to create an accessible <video>
element for a regular HLS video stream. However, I noticed that there is no cross-browser way to specify multiple audio tracks and switch between them efficiently, like you can with closed-captions.
我已经考虑过 audioTrack
属性,但这不适用于许多浏览器。我也尝试过 mediaGroup
,它也不兼容跨浏览器。
I've considered the audioTrack
property but this does not work on many browsers. I've tried mediaGroup
as well, which is also not cross-browser compatible.
我唯一的选择是我们已经看到可能可行的方法是 video.js
( https://docs.videojs.com/docs/guides/audio-tracks.html ),但我想知道是否有一种无需引入此库的方法。
The only thing I've seen that may work is video.js
(https://docs.videojs.com/docs/guides/audio-tracks.html), but I was wondering if there was a way to do this without bringing in this library.
似乎很奇怪,如果没有图书馆,您将无法做到这一点。
Seems odd that you wouldn't be able to do this without a library.
最终目标是通过编程
推荐答案
如果在所有(大多数)浏览器中都可以在HTML5视频中切换不同语言的音频轨道。
If I understand you correctly, you want to be able to switch between languages on a video track. I found this bit of code that has a main audio track of English and allows you to switch between English and French. You can read more about it at https:gingertech.net
<video id="v1" poster="video.png" controls>
<source src="video.ogv" type="video/ogg">
<source src="video.mp4" type="video/mp4">
</video>
<script type="text/javascript">
video = document.getElementsByTagName("video")[0];
for (i=0; i < video.audioTracks.length; i++) {
if (video.audioTracks[i].language.substring(0,2) === "fr") {
video.audioTracks[i].enabled = true;
} else {
video.audioTracks[i].enabled = false;
}
}
</script>
这篇关于在< video>上播放多个音轨;元件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!