admin管理员组文章数量:1405332
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'
});
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
from the docs: .html
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'
});
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
from the docs: http://docs.videojs./docs/guides/audio-tracks.html
Share Improve this question edited Jan 30, 2018 at 7:40 Blurry Script asked Jan 30, 2018 at 7:22 Blurry ScriptBlurry Script 2631 gold badge3 silver badges12 bronze badges 02 Answers
Reset to default 3Audio src under the <audio controls>
then <source>
tag. You should define here or create dynamically this elements.
You can download example sounds here.
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/5.15/video.js"></script>
<link href="https://vjs.zencdn/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./html/horse.ogg" type="audio/ogg">
</audio>
Dynamically;
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./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/5.15/video.js"></script>
<link href="https://vjs.zencdn/5.15/video-js.css" rel="stylesheet"/>
<body>
</body>
It is not possible to add audio tracks through HTML like you can with text tracks. They must be added programmatically. Video.js only stores track representations. Switching audio tracks for playback is not handled by Video.js and must be handled elsewhere - for example, videojs-contrib-hls handles switching audio tracks to support track selection through the UI.
Reference: https://docs.videojs./tutorial-audio-tracks.html
本文标签: javascriptHow to add an audiotrack in videojsStack Overflow
版权声明:本文标题:javascript - How to add an audiotrack in video.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744330894a2600959.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论