Dash.js - Trapping 404 errors from MPEG-DASH player

3k views Asked by At

I've using the Dash.js player to play MPEG-DASH videos. The videos are pulled from a server. Every now and then there will be 404 errors due to server issues, I would like to retry the stream in the background by detecting the 404 error and acting accordingly.

The problem is I cannot catch the error, it's thrown from the line

req.send();

Which is in a file called FragmentLoader.js.

I've tried the following error handling:

window.addEventListener('error', function(e) {
    console.log("Item: " + e.message);
}, true);

var oReq = new XMLHttpRequest();
oReq.addEventListener("error", function (e) {
    console.log("xml item: " + e.message);
}, true);


$(document).ajaxError(function (event, xhr, ajaxOptions, errorThrown) {
    alert("ajax erorr");
});

However none of these conditions catch the error. Is there any way to catch these errors thrown from the dash.js player?

2

There are 2 answers

0
Jeff On

its been a bit since i've been in that code, but if memory serves, you should be able to determine it is a 404 by checking the status property of the error

var oReq = new XMLHttpRequest();
oReq.addEventListener("error", function (e) {
    console.log("xml item: " + e.status);
}, true);
0
LloydW On

Dash.js has internal retry logic on a 404 - it will retry 3 times (so a total of 4 attempts) before giving up. There's some discussion about improving this behaviour further such as trying the other available representations, but that isn't there yet.

However, this depends on the 404 being detected by the page. There are some XHR errors that are completely silent in terms of what JavaScript can see, even though an error is logged to the console on the exact line of req.send(), which is behaviour I've seen here: https://github.com/Dash-Industry-Forum/dash.js/issues/1209

If the request is indeed throwing a 404 that Dash.js' error handling has handled, retried, and then gave up, then you can bind to its error event:

var url = "http://dash.edgesuite.net/envivio/Envivio-dash2/manifest.mpd";
var player = dashjs.MediaPlayer().create();
player.initialize(document.querySelector("#videoPlayer"), url, true);
player.on('error', function(e) {
    if (e.error === 'download') {
        // dash.js gave up loading something
        // e.event.id will tell you what it failed to load (mpd, segment...)
        // and e.event.url will have the URL that failed
    }
});