4495a3f6 by Tom Johnson

stub event handling for playlist/segment 404 w tests

1 parent 10a996a2
......@@ -177,6 +177,14 @@ var
fillBuffer(currentTime * 1000);
});
player.on('hls-missing-segment', function() {
//console.log('Missing Segment Triggered');
});
player.on('hls-missing-playlist', function() {
//console.log('Missing Playlist Triggered');
});
/**
* Chooses the appropriate media playlist based on the current
* bandwidth estimate and the player size.
......@@ -234,6 +242,11 @@ var
xhr.onreadystatechange = function() {
var i, parser, playlist, playlistUri;
if (xhr.status === 404) {
player.trigger('hls-missing-playlist', url);
return;
}
if (xhr.readyState === 4) {
// readystate DONE
parser = new videojs.m3u8.Parser();
......@@ -348,6 +361,11 @@ var
segmentXhr.onreadystatechange = function() {
var playlist;
if (this.status === 404) {
player.trigger('hls-missing-segment');
return;
}
if (this.readyState === 4) {
// the segment request is no longer outstanding
segmentXhr = null;
......
......@@ -547,6 +547,59 @@ test('gets the correct PTS on seek', function() {
ok(ptsByTime<=seekTime, 'PTS should be less than or equal to seek time');
});
test('missing playlist should trigger error', function() {
var errorTriggered = false;
window.XMLHttpRequest = function() {
this.open = function(method, url) {
xhrUrls.push(url);
};
this.send = function() {
this.status = 404;
this.onreadystatechange();
};
};
player.hls('manifest/media.m3u8');
player.on('hls-missing-playlist', function() {
errorTriggered = true;
});
videojs.mediaSources[player.currentSrc()].trigger({
type: 'sourceopen'
});
equal(true, errorTriggered, 'Missing Playlist error event should trigger');
});
test('missing segment should trigger error', function() {
var errorTriggered = false;
player.hls('manifest/media.m3u8');
player.on('loadedmanifest', function() {
window.XMLHttpRequest = function() {
this.open = function(method, url) {
xhrUrls.push(url);
};
this.send = function() {
this.status = 404;
this.onreadystatechange();
};
};
});
player.on('hls-missing-segment', function() {
errorTriggered = true;
});
videojs.mediaSources[player.currentSrc()].trigger({
type: 'sourceopen'
});
equal(true, errorTriggered, 'Missing Segment error event should trigger');
});
module('segment controller', {
setup: function() {
......