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 ...@@ -185,6 +185,14 @@ var
185 //console.log('Missing Playlist Triggered'); 185 //console.log('Missing Playlist Triggered');
186 }); 186 });
187 187
188 player.on('error', function() {
189 if(player.error)
190 {
191 console.log(player.error.message);
192 }
193
194 });
195
188 /** 196 /**
189 * Chooses the appropriate media playlist based on the current 197 * Chooses the appropriate media playlist based on the current
190 * bandwidth estimate and the player size. 198 * bandwidth estimate and the player size.
...@@ -242,12 +250,18 @@ var ...@@ -242,12 +250,18 @@ var
242 xhr.onreadystatechange = function() { 250 xhr.onreadystatechange = function() {
243 var i, parser, playlist, playlistUri; 251 var i, parser, playlist, playlistUri;
244 252
245 if (xhr.status === 404) { 253 if (xhr.readyState === 4) {
246 player.trigger('hls-missing-playlist', url); 254 if (xhr.status >= 400) {
255 player.error = {
256 type: 'hls-missing-playlist',
257 status: xhr.status,
258 message: 'HLS Missing Playlist at URL: ' + url,
259 code: (xhr.status >= 500) ? 4 : 2
260 };
261 player.trigger('error');
247 return; 262 return;
248 } 263 }
249 264
250 if (xhr.readyState === 4) {
251 // readystate DONE 265 // readystate DONE
252 parser = new videojs.m3u8.Parser(); 266 parser = new videojs.m3u8.Parser();
253 parser.push(xhr.responseText); 267 parser.push(xhr.responseText);
...@@ -361,12 +375,26 @@ var ...@@ -361,12 +375,26 @@ var
361 segmentXhr.onreadystatechange = function() { 375 segmentXhr.onreadystatechange = function() {
362 var playlist; 376 var playlist;
363 377
364 if (this.status === 404) { 378 if (this.readyState === 4) {
365 player.trigger('hls-missing-segment'); 379 if (this.status >= 400) {
380 console.log('index', player.hls.mediaIndex, player.hls.media.segments.length);
381 if(player.hls.mediaIndex<player.hls.media.segments.length-1)
382 {
383 player.hls.mediaIndex++;
384 segmentXhr = null;
385 fillBuffer();
386 } else {
387 player.error = {
388 type: 'hls-missing-segment',
389 message: 'HLS Missing Segment at index ' + player.hls.mediaIndex,
390 status: this.status,
391 code: (this.status >= 500) ? 4 : 2
392 };
393 player.trigger('error');
394 }
366 return; 395 return;
367 } 396 }
368 397
369 if (this.readyState === 4) {
370 // the segment request is no longer outstanding 398 // the segment request is no longer outstanding
371 segmentXhr = null; 399 segmentXhr = null;
372 400
......
...@@ -555,6 +555,7 @@ test('missing playlist should trigger error', function() { ...@@ -555,6 +555,7 @@ test('missing playlist should trigger error', function() {
555 xhrUrls.push(url); 555 xhrUrls.push(url);
556 }; 556 };
557 this.send = function() { 557 this.send = function() {
558 this.readyState = 4;
558 this.status = 404; 559 this.status = 404;
559 this.onreadystatechange(); 560 this.onreadystatechange();
560 }; 561 };
...@@ -562,8 +563,10 @@ test('missing playlist should trigger error', function() { ...@@ -562,8 +563,10 @@ test('missing playlist should trigger error', function() {
562 563
563 player.hls('manifest/media.m3u8'); 564 player.hls('manifest/media.m3u8');
564 565
565 player.on('hls-missing-playlist', function() { 566 player.on('error', function() {
567 if (player.error.code === 2) {
566 errorTriggered = true; 568 errorTriggered = true;
569 }
567 }); 570 });
568 571
569 videojs.mediaSources[player.currentSrc()].trigger({ 572 videojs.mediaSources[player.currentSrc()].trigger({
...@@ -584,14 +587,17 @@ test('missing segment should trigger error', function() { ...@@ -584,14 +587,17 @@ test('missing segment should trigger error', function() {
584 xhrUrls.push(url); 587 xhrUrls.push(url);
585 }; 588 };
586 this.send = function() { 589 this.send = function() {
590 this.readyState = 4;
587 this.status = 404; 591 this.status = 404;
588 this.onreadystatechange(); 592 this.onreadystatechange();
589 }; 593 };
590 }; 594 };
591 }); 595 });
592 596
593 player.on('hls-missing-segment', function() { 597 player.on('error', function () {
598 if (player.error.code === 2) {
594 errorTriggered = true; 599 errorTriggered = true;
600 }
595 }); 601 });
596 602
597 videojs.mediaSources[player.currentSrc()].trigger({ 603 videojs.mediaSources[player.currentSrc()].trigger({
......