0fa1bd7c by Tom Johnson

implement advanced 404 segment routine. update player.error object with details …

…of segment/manifest 404. update tests
1 parent 4495a3f6
......@@ -185,6 +185,14 @@ var
//console.log('Missing Playlist Triggered');
});
player.on('error', function() {
if(player.error)
{
console.log(player.error.message);
}
});
/**
* Chooses the appropriate media playlist based on the current
* bandwidth estimate and the player size.
......@@ -242,12 +250,18 @@ var
xhr.onreadystatechange = function() {
var i, parser, playlist, playlistUri;
if (xhr.status === 404) {
player.trigger('hls-missing-playlist', url);
return;
}
if (xhr.readyState === 4) {
if (xhr.status >= 400) {
player.error = {
type: 'hls-missing-playlist',
status: xhr.status,
message: 'HLS Missing Playlist at URL: ' + url,
code: (xhr.status >= 500) ? 4 : 2
};
player.trigger('error');
return;
}
// readystate DONE
parser = new videojs.m3u8.Parser();
parser.push(xhr.responseText);
......@@ -361,12 +375,26 @@ var
segmentXhr.onreadystatechange = function() {
var playlist;
if (this.status === 404) {
player.trigger('hls-missing-segment');
return;
}
if (this.readyState === 4) {
if (this.status >= 400) {
console.log('index', player.hls.mediaIndex, player.hls.media.segments.length);
if(player.hls.mediaIndex<player.hls.media.segments.length-1)
{
player.hls.mediaIndex++;
segmentXhr = null;
fillBuffer();
} else {
player.error = {
type: 'hls-missing-segment',
message: 'HLS Missing Segment at index ' + player.hls.mediaIndex,
status: this.status,
code: (this.status >= 500) ? 4 : 2
};
player.trigger('error');
}
return;
}
if (this.readyState === 4) {
// the segment request is no longer outstanding
segmentXhr = null;
......
......@@ -555,6 +555,7 @@ test('missing playlist should trigger error', function() {
xhrUrls.push(url);
};
this.send = function() {
this.readyState = 4;
this.status = 404;
this.onreadystatechange();
};
......@@ -562,8 +563,10 @@ test('missing playlist should trigger error', function() {
player.hls('manifest/media.m3u8');
player.on('hls-missing-playlist', function() {
errorTriggered = true;
player.on('error', function() {
if (player.error.code === 2) {
errorTriggered = true;
}
});
videojs.mediaSources[player.currentSrc()].trigger({
......@@ -584,14 +587,17 @@ test('missing segment should trigger error', function() {
xhrUrls.push(url);
};
this.send = function() {
this.readyState = 4;
this.status = 404;
this.onreadystatechange();
};
};
});
player.on('hls-missing-segment', function() {
errorTriggered = true;
player.on('error', function () {
if (player.error.code === 2) {
errorTriggered = true;
}
});
videojs.mediaSources[player.currentSrc()].trigger({
......