Error handling
When an error condition occurs Viblast tries to recover from it in a manner that would disturb viewer experience the least. For example if a segment of the stream cannot be transfered Viblast will retry. If after a certain time the segment still cannot be downloaded then Viblast will try to skip it and continue with the stream after the missing segment.
However sometimes it's useful to know if such an error condition has occurred. For these cases Viblast fires specific events on the on the viblast
api object.
The Transfer Failure Event
When the transfer of a segment, HLS playlist or MPD fails, Viblast fires the transferfailure
event.
var player = document.getElementById('my-player');
player.viblast.addEventListener('transferfailure', function(ev) {
console.log('transfer of', ev.url, 'failed with', ev.status, ' response body:', ev.body);
});
url
is the url of the HTTP request that failedstatus
is the HTTP status code of the server responsebody
is the HTTP response body of the server response
Special status codes
It is possible for the player to discard the stream requests internally in case of the ABR algorithm quality switching, seek performed or timeout achieved. When the request is internally terminated, the application gets notified about transfer failure with non HTTP status code, but with special negative one.
-524
is a notification for a request terminated because of a timeout-523
is a notification for a request which is aborted because the segment is not needed anymore. This might happen if the seek is performed, quality is switched or the chunk download is too slow for live streams and the player decides to move forward.-522
is a notification for a request which contains no data, but its status code is 200 or 206.
Here is the equivalent code when videojs
is used.
var player = videojs('my-player');
player.viblast.addEventListener('transferfailure', function(ev) {
console.log('transfer of', ev.url, 'failed with', ev.status, ' response body:', ev.body);
});
You can find an example demoing how to use transferfailure
in our codepen page.
This API is available since version 6.24.