我正在像这样将无效源加载到 videojs 播放器实例中:
player.src({
src: 'http://example.com/invalid',
type: 'audio/mp4',
});
然后我尝试按如下方式捕获发生的错误:
player.on('error', () => {
console.log(player.error); //Gives MEDIA_ERR_SRC_NOT_SUPPORTED error
})
这给了我 videojs 内部抛出的错误,但不是导致它的错误。在我的应用程序中,如果您尝试加载不应该加载的源,我使用的 API 会抛出特定的错误代码。我怎么能捕捉到这样的错误。
最佳答案
I would like to catch the first error in the screenshot below:
你不能。当 video
元素中的 src
属性元素发生变化时调用。
const playerElement = document.querySelector("#player")
playerElement.addEventListener("error", (event) => {
console.log(event.target.error.message);
})
const player = videojs('player');
player.src({
src: 'http://example.com/invalid',
type: 'audio/mp4',
});
<script src="https://vjs.zencdn.net/7.7.6/video.js"></script>
<video id="player" ></video>
关于javascript - 使用 videojs 捕获无效源错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61878817/