📅  最后修改于: 2023-12-03 14:41:51.879000             🧑  作者: Mango
HTML | DOM 音频 audioTracks 属性表示了音频轨道(audio track)的列表。音频轨道可以包含多个声音源,如不同语言的音频轨道或者不同的音频效果。
let audio = document.getElementById("myAudio");
let audioTrackList = audio.audioTracks;
// 遍历音频轨道列表
for (let i = 0; i < audioTrackList.length; i++) {
console.log(audioTrackList[i].label);
}
let audio = document.getElementById("myAudio");
let audioTrackList = audio.audioTracks;
// 添加一个音频轨道
let newTrack = new AudioTrack();
// 设置音频轨道的属性
newTrack.enabled = true;
newTrack.language = "en";
audioTrackList.addTrack(newTrack);
// 删除一个音频轨道
audioTrackList.removeTrack(newTrack);
let audio = document.getElementById("myAudio");
let audioTrackList = audio.audioTracks;
audioTrackList.onaddtrack = function(event) {
console.log("音频轨道已添加");
};
audioTrackList.onremovetrack = function(event) {
console.log("音频轨道已删除");
};
audioTrackList.onchange = function(event) {
console.log("音频轨道状态已改变");
};
| Chrome | Firefox | Safari | Opera | Edge | Internet Explorer | | ------ | ------- | ------ | ----- | ---- | ----------------- | | 49+ | 48+ | 11.1+ | 36+ | 79+ | 不支持 |
注意:Internet Explorer 不支持
audioTracks
属性。