Not sure if this is the best place to ask, sorry if not.
I'm looking to override the player's default handling of network errors.
In short, in the case where playback has already begun, if the player gets a network error refetching the manifest, or when fetching a ts segment, its default behavior is to throw a fatal error.
I'd like to configure the player so that it rather goes into a loading state and continues retrying until the network (hopefully) comes back up and playback can resume seamlessly.
Is it possible to accomplish the with configuration only, or would it require modifying source code? If the latter, can anyone recommend where to start digging into the code?
Thanks for any guidance!
hls.on(hlsjs.Events.ERROR, (event, data) => {
switch (data.type) {
case hlsjs.ErrorTypes.NETWORK_ERROR: // playlist file 404'd (probably), wait 1 second and retry
console.log("network error on playlist load, retrying in 1 second.");
this.hlsTryLoadTimer = setTimeout(() => this.hlsTryLoad(), 1000);
}
});
hlsTryLoad() {
this.hlsInstance.loadSource(this.url);
this.hlsInstance.startLoad();
}
Beautiful. Will try this out. Thanks, Thomas!
Hey @thomasbarronchurchill,
It looks like this method reloads the manifest from scratch, which causes the player to lose its place when the network comes back online.
Is it possible to catch the fatal error before it bubbles up to the point of necessitating reloading the manifest?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi @kad3nce,
What you can do is increase the number of retries, and/or change the level on error.
The config options for retries and timeouts are:
https://github.com/video-dev/hls.js/blob/master/docs/API.md#fragloadingmaxretry--manifestloadingmaxretry--levelloadingmaxretry
fragLoadingMaxRetry / manifestLoadingMaxRetry / levelLoadingMaxRetry
fragLoadingMaxRetryTimeout / manifestLoadingMaxRetryTimeout / levelLoadingMaxRetryTimeout
fragLoadingRetryDelay / manifestLoadingRetryDelay / levelLoadingRetryDelay
fragLoadingTimeOut / manifestLoadingTimeOut / levelLoadingTimeOut
To do a level switch or remove a level that failed:
https://github.com/video-dev/hls.js/blob/master/demo/main.js#L799
Start load is only needed to recover from a network error where the parent manifest failed to load (you don't and shouldn't call hls.loadSource(url) again without destroying the player until these changes make it into a release.
hls.startLoad()
To recover from a media error (similar to the solution above) see the demo implementation:
https://github.com/video-dev/hls.js/blob/master/demo/main.js#L814
This will reset the source buffers
hls.recoverMediaError();
Thanks, @robwalch!
Most helpful comment