我正在学习HTML媒体。有一个检测轨道添加的示例:
const mediaElem = document.querySelector("video");
mediaElem.audioTracks.onaddtrack = function(event) {
audioTrackAdded(event.track);
}
我的HTML代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Multimedia</title>
</head>
<body>
<video controls loop muted poster="images/poster.png"
width="400" height="400">
<source src="videos/rabbit320.webm" type="video/webm">
<source src="videos/rabbit320.mp4" type="video/mp4">
<p>
Your browser doesn't support HTML5 audio. Here is a <a href="audio/viper.mp3">link to the audio</a> instead.
</p>
</video>
<script src="scripts/script.js"></script>
</body>
</html>
和JS代码( script.js ):
var videoElem = document.querySelector('video');
videoElem.audioTracks.onaddtrack = function (event) {
console.log(event.track);
};
在控制台中,我收到此错误:
未捕获的TypeError:无法在script.js:2上设置未定义的属性“ onaddtrack”
我在做什么错了?
答案 0 :(得分:0)
HTMLMediaElement.audioTracks属性仍位于标志后面,如此处https://caniuse.com/#feat=audiotracks
所述MDN上的兼容性表可能未正确显示Opera支持的功能。