如何在 video.js 中添加音轨? [英] How to add an audiotrack in video.js?
本文介绍了如何在 video.js 中添加音轨?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 video.js 的示例中,我发现了这一点:
in the examples of video.js I've found this:
var track = new videojs.AudioTrack({
id: 'my-spanish-audio-track',
kind: 'translation',
label: 'Spanish',
language: 'es'
});
我的问题是,如果没有 src
属性,它是如何添加的,它从哪里获取轨道本身?我的意思是源本身像 mp3
或 wav
文件
my question is how it is added if there are no src
attribute, from where does it get the track itself? I mean the source itself like mp3
or wav
file
来自文档:http://docs.videojs.com/docs/guides/audio-tracks.html
推荐答案
然后
标签下的Audio src.您应该在此处定义或动态创建此元素.
Audio src under the <audio controls>
then <source>
tag. You should define here or create dynamically this elements.
您可以在此处下载示例声音.
var player = videojs('my-player');
// Create a track object.
var track = new videojs.AudioTrack({
id: 'my-spanish-audio-track',
kind: 'translation',
label: 'Spanish',
language: 'es'
});
// Add the track to the player's audio track list.
player.audioTracks().addTrack(track);
<script src="https://vjs.zencdn.net/5.15/video.js"></script>
<link href="https://vjs.zencdn.net/5.15/video-js.css" rel="stylesheet" />
<audio id="my-player" class="video-js" controls>
<source id="my-spanish-audio-track" src="https://www.w3schools.com/html/horse.ogg" type="audio/ogg">
</audio>
动态;
var myAudio=document.createElement("audio");
myAudio.id="my-player";
myAudio.className="video-js";
myAudio.setAttribute("controls",true);
var mySource1=document.createElement("source");
mySource1.id="my-spanish-audio-track";
mySource1.src="https://www.w3schools.com/html/horse.ogg";
mySource1.type="audio/ogg";
myAudio.appendChild(mySource1);
document.body.appendChild(myAudio);
var player = videojs('my-player');
// Create a track object.
var track = new videojs.AudioTrack({
id: 'my-spanish-audio-track',
kind: 'translation',
label: 'Spanish',
language: 'es'
});
// Add the track to the player's audio track list.
player.audioTracks().addTrack(track);
<script src="https://vjs.zencdn.net/5.15/video.js"></script>
<link href="https://vjs.zencdn.net/5.15/video-js.css" rel="stylesheet"/>
<body>
</body>
这篇关于如何在 video.js 中添加音轨?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文