4495a3f6 by Tom Johnson

stub event handling for playlist/segment 404 w tests

1 parent 10a996a2
...@@ -177,6 +177,14 @@ var ...@@ -177,6 +177,14 @@ var
177 fillBuffer(currentTime * 1000); 177 fillBuffer(currentTime * 1000);
178 }); 178 });
179 179
180 player.on('hls-missing-segment', function() {
181 //console.log('Missing Segment Triggered');
182 });
183
184 player.on('hls-missing-playlist', function() {
185 //console.log('Missing Playlist Triggered');
186 });
187
180 /** 188 /**
181 * Chooses the appropriate media playlist based on the current 189 * Chooses the appropriate media playlist based on the current
182 * bandwidth estimate and the player size. 190 * bandwidth estimate and the player size.
...@@ -234,6 +242,11 @@ var ...@@ -234,6 +242,11 @@ var
234 xhr.onreadystatechange = function() { 242 xhr.onreadystatechange = function() {
235 var i, parser, playlist, playlistUri; 243 var i, parser, playlist, playlistUri;
236 244
245 if (xhr.status === 404) {
246 player.trigger('hls-missing-playlist', url);
247 return;
248 }
249
237 if (xhr.readyState === 4) { 250 if (xhr.readyState === 4) {
238 // readystate DONE 251 // readystate DONE
239 parser = new videojs.m3u8.Parser(); 252 parser = new videojs.m3u8.Parser();
...@@ -348,6 +361,11 @@ var ...@@ -348,6 +361,11 @@ var
348 segmentXhr.onreadystatechange = function() { 361 segmentXhr.onreadystatechange = function() {
349 var playlist; 362 var playlist;
350 363
364 if (this.status === 404) {
365 player.trigger('hls-missing-segment');
366 return;
367 }
368
351 if (this.readyState === 4) { 369 if (this.readyState === 4) {
352 // the segment request is no longer outstanding 370 // the segment request is no longer outstanding
353 segmentXhr = null; 371 segmentXhr = null;
......
...@@ -547,6 +547,59 @@ test('gets the correct PTS on seek', function() { ...@@ -547,6 +547,59 @@ test('gets the correct PTS on seek', function() {
547 ok(ptsByTime<=seekTime, 'PTS should be less than or equal to seek time'); 547 ok(ptsByTime<=seekTime, 'PTS should be less than or equal to seek time');
548 }); 548 });
549 549
550 test('missing playlist should trigger error', function() {
551 var errorTriggered = false;
552
553 window.XMLHttpRequest = function() {
554 this.open = function(method, url) {
555 xhrUrls.push(url);
556 };
557 this.send = function() {
558 this.status = 404;
559 this.onreadystatechange();
560 };
561 };
562
563 player.hls('manifest/media.m3u8');
564
565 player.on('hls-missing-playlist', function() {
566 errorTriggered = true;
567 });
568
569 videojs.mediaSources[player.currentSrc()].trigger({
570 type: 'sourceopen'
571 });
572
573 equal(true, errorTriggered, 'Missing Playlist error event should trigger');
574 });
575
576 test('missing segment should trigger error', function() {
577 var errorTriggered = false;
578
579 player.hls('manifest/media.m3u8');
580
581 player.on('loadedmanifest', function() {
582 window.XMLHttpRequest = function() {
583 this.open = function(method, url) {
584 xhrUrls.push(url);
585 };
586 this.send = function() {
587 this.status = 404;
588 this.onreadystatechange();
589 };
590 };
591 });
592
593 player.on('hls-missing-segment', function() {
594 errorTriggered = true;
595 });
596
597 videojs.mediaSources[player.currentSrc()].trigger({
598 type: 'sourceopen'
599 });
600
601 equal(true, errorTriggered, 'Missing Segment error event should trigger');
602 });
550 603
551 module('segment controller', { 604 module('segment controller', {
552 setup: function() { 605 setup: function() {
......