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();
}
I am trying to use this code to stream videos to users, but I get an error, if there are no stream and the app crashes.
Unhandled Rejection (AbortError): The fetching process for the media resource was aborted by the user agent at the user's request.
The error is thrown when I try to execute this:
player.attachMediaElement(videoRef.current);
Is there a way to check if this line is going to throw an error?
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();
}
I am trying to use this code to stream videos to users, but I get an error, if there are no stream and the app crashes.
Unhandled Rejection (AbortError): The fetching process for the media resource was aborted by the user agent at the user's request.
The error is thrown when I try to execute this:
player.attachMediaElement(videoRef.current);
Is there a way to check if this line is going to throw an error?
Share Improve this question edited Sep 8, 2023 at 1:22 ggorlen 57.1k8 gold badges110 silver badges150 bronze badges asked Jul 17, 2020 at 23:19 user11092881user11092881 2- Are you using this library? github./bilibili/flv.js/blob/master/docs/api.md – David Rissato Cruz Commented Jul 17, 2020 at 23:23
- Yes, I tried enclosing the code in a try catch and it still crashes. – user11092881 Commented Jul 17, 2020 at 23:26
1 Answer
Reset to default 13This type of error (Unhandled Rejection
) tells us you have a rejected Promise that is not being properly handled.
Promises are asynchronous, and the error will happen asynchronously as well.
According to the library documentation (here), the only method that returns a Promise is method play
.
So I guess that you are probably invoking play
method in a different part of your code. And you need to capture the error there, as in:
flvPlayer.play().catch((e)=>{
/* error handler */
})