gpt4 book ai didi

javascript - 如何在 video.js 中添加音轨?

转载 作者:行者123 更新时间:2023-12-04 13:03:22 26 4
gpt4 key购买 nike

在 video.js 的示例中,我发现了这一点:

var track = new videojs.AudioTrack({
id: 'my-spanish-audio-track',
kind: 'translation',
label: 'Spanish',
language: 'es'
});

我的问题是如果没有 src 是如何添加的属性,它从哪里获得轨道本身?我的意思是源本身,如 mp3wav文件

来自文档: http://docs.videojs.com/docs/guides/audio-tracks.html

最佳答案

<audio controls>下的音频src然后 <source>标签。您应该在此处定义或动态创建此元素。

您可以下载示例声音 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.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>

关于javascript - 如何在 video.js 中添加音轨?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48515994/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com