我正在尝试使用像这样的webvtt元素显示录音的字幕:
<audio controls="controls">
<source src="TheBrigands.mp3" />
<source src="TheBrigands.ogg" />
<track default="" kind="subtitles" srclang="en" label="English text" src="TheBrigands.vtt" />
</audio>
<div id="display">
It was a cold and stormy night,
</div>
使用此脚本填充显示div:
<script>
function main() {
var recording = document.querySelector("audio");
var track = recording.textTracks[0];
var display = document.getElementById("display");
track.mode = "hidden";
track.oncuechange = function () {
var cue = this.activeCues[0];
display.innerHTML = cue.text;
}
}
window.onload = main;
</script>
然而,当我在firefox中检查轨道时,虽然它有一个提示对象,但它是空的:
document.querySelector('track').track.cues
TextTrackCueList { length: 0 }
我检查过,我在服务器中正确配置了mime-type。
我错过了什么导致它无法加载?