Unhandled Rejection (AbortError): The fetching process for the media resource was aborted by the user agent at the user's request

Viewed 10411

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?

1 Answers

This 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 */
})
Related