muxinc / hls-video-element

A custom element (web component) for playing HTTP Live Streaming (HLS) videos.
https://hls-video-element-mux.vercel.app
MIT License
38 stars 18 forks source link

Manage error like Hls do #12

Closed Nodalailama closed 11 months ago

Nodalailama commented 2 years ago

Hi,

It should be great to manage error like hls doc suggère, see https://github.com/video-dev/hls.js/blob/master/docs/API.md#fifth-step-error-handling.

hls.on(Hls.Events.ERROR, function (event, data) {
  var errorType = data.type;
  var errorDetails = data.details;
  var errorFatal = data.fatal;

  switch (data.details) {
    case Hls.ErrorDetails.FRAG_LOAD_ERROR:
      // ....
      break;
    default:
      break;
  }
});
hls.on(Hls.Events.ERROR, function (event, data) {
  if (data.fatal) {
    switch (data.type) {
      case Hls.ErrorTypes.NETWORK_ERROR:
        // try to recover network error
        console.log('fatal network error encountered, try to recover');
        hls.startLoad();
        break;
      case Hls.ErrorTypes.MEDIA_ERROR:
        console.log('fatal media error encountered, try to recover');
        hls.recoverMediaError();
        break;
      default:
        // cannot recover
        hls.destroy();
        break;
    }
  }
});

Cordialement,

PS: I could have propose a PR for this and the 2 other issues I submitted today but I haven't done before ...

luwes commented 11 months ago

thanks for the feedback.

the hls.js code snippet was actually quite outdated. have a look here for more info on that https://github.com/muxinc/elements/pull/111