hls.js icon indicating copy to clipboard operation
hls.js copied to clipboard

hls.js not retrying when manifest request returns 404

Open twilson90 opened this issue 1 year ago • 3 comments

What do you want to do with Hls.js?

I've also tried setting the manifestLoadPolicy -> errorRetry -> maxNumRetry = 10 No different. It tries once and completely gives up. In my case the server hasn't generated a manifest yet so it sends a 404 until it's ready. Why does hls.js not handle 404 errors?

What have you tried so far?

twilson90 avatar Apr 02 '24 16:04 twilson90

This is the expected behavior for 4xx errors.

You need to add a shouldRetry callback filter to return true for 404s if you want to keep requesting a URL that could not be found.

https://github.com/video-dev/hls.js/blob/master/docs/API.md#shouldretry

https://hlsjs.video-dev.org/api-docs/hls.js.retryconfig

robwalch avatar Apr 02 '24 16:04 robwalch

@twilson90 you ever get this working? Looking for a similar solution. Didn't know if you had some code you could share. I'm using Vidstack.

thekendog avatar Sep 23 '24 19:09 thekendog

This is what a custom shouldRetry callback for manifest request errors look like:

new Hls({
  manifestLoadPolicy: {
    default: {
      maxTimeToFirstByteMs: Infinity,
      maxLoadTimeMs: 20000,
      timeoutRetry: {
        maxNumRetry: 3,
        retryDelayMs: 0,
        maxRetryDelayMs: 0,
      },
      errorRetry: {
        maxNumRetry: 2,
        retryDelayMs: 1000,
        maxRetryDelayMs: 8000,
        shouldRetry: (
          retryConfig,
          retryCount,
          isTimeout,
          loaderResponse,
          retry,
// Tailor the result to customize retry logic.
// HTTP status `loaderResponse.code` is ignored in this example:
        ) => retryCount < retryConfig.maxNumRetry
      },
    },
  },

robwalch avatar Sep 23 '24 22:09 robwalch