https://onoumenon.gitbook.io/wiki/programming/tips/rtmp
buildPlayer() {
if (this.player || !this.props.stream) {
return;
}
const { id } = this.props.match.params;
this.player = flv.createPlayer({
type: "flv",
url: `http://localhost:8000/live/${id}.flv`
});
this.player.attachMediaElement(this.videoRef.current);
this.player.load();
}
我正在尝试使用此代码向用户流式传输视频,但如果没有流式传输并且应用程序崩溃,则会收到错误消息。
未处理的拒绝 (AbortError):用户代理应用户请求中止了媒体资源的获取过程。
当我尝试执行时抛出错误:
player.attachMediaElement(videoRef.current);
有没有办法检查这条线是否会抛出错误?
最佳答案
这种类型的错误(Unhandled Rejection
)告诉我们您有一个被拒绝的 Promise 没有被正确处理。
Promise 是异步的,错误也会异步发生。
根据库文档 (here),返回 Promise 的唯一方法是方法 play
。
所以我猜您可能在代码的不同部分调用了 play
方法。你需要在那里捕获错误,如:
flvPlayer.play().catch((e)=>{
/* error handler */
})
关于javascript - 未处理的拒绝 (AbortError) : The fetching process for the media resource was aborted by the user agent at the user's request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62962936/