e528f83b by Tom Johnson

Merge branch 'feature/basic-playback' of github.com:brightcove/videojs-contrib-h…

…ls into feature/basic-playback
2 parents 9d311e27 b713aa5b
...@@ -292,11 +292,10 @@ var ...@@ -292,11 +292,10 @@ var
292 // always start playback with the default rendition 292 // always start playback with the default rendition
293 if (!player.hls.media) { 293 if (!player.hls.media) {
294 player.hls.media = player.hls.master.playlists[0]; 294 player.hls.media = player.hls.master.playlists[0];
295 if (parser.manifest.totalDuration) { 295
296 // update the duration 296 // update the duration
297 if (parser.manifest.totalDuration) {
297 player.duration(parser.manifest.totalDuration); 298 player.duration(parser.manifest.totalDuration);
298 // Notify the flash layer
299 //player.el().querySelector('.vjs-tech').vjs_setProperty('duration',parser.manifest.totalDuration);
300 } else { 299 } else {
301 player.duration(totalDuration(parser.manifest)); 300 player.duration(totalDuration(parser.manifest));
302 } 301 }
...@@ -311,8 +310,9 @@ var ...@@ -311,8 +310,9 @@ var
311 downloadPlaylist(resolveUrl(srcUrl, playlist.uri)); 310 downloadPlaylist(resolveUrl(srcUrl, playlist.uri));
312 } else { 311 } else {
313 player.hls.media = playlist; 312 player.hls.media = playlist;
314 if (player.hls.media.totalDuration) { 313
315 // update the duration 314 // update the duration
315 if (player.hls.media.totalDuration) {
316 player.duration(player.hls.media.totalDuration); 316 player.duration(player.hls.media.totalDuration);
317 } else { 317 } else {
318 player.duration(totalDuration(player.hls.media)); 318 player.duration(totalDuration(player.hls.media));
...@@ -370,28 +370,25 @@ var ...@@ -370,28 +370,25 @@ var
370 segmentXhr.onreadystatechange = function() { 370 segmentXhr.onreadystatechange = function() {
371 var playlist; 371 var playlist;
372 372
373 if (this.readyState === 4) { 373 // wait until the request completes
374 if (this.status >= 400) { 374 if (this.readyState !== 4) {
375 if(player.hls.mediaIndex<player.hls.media.segments.length-1) 375 return;
376 { 376 }
377 player.hls.mediaIndex++; 377
378 // the segment request is no longer outstanding
378 segmentXhr = null; 379 segmentXhr = null;
379 fillBuffer(); 380
380 } else { 381 // trigger an error if the request was not successful
381 player.error = { 382 if (this.status >= 400) {
382 type: 'hls-missing-segment', 383 player.hls.error = {
383 message: 'HLS Missing Segment at index ' + player.hls.mediaIndex,
384 status: this.status, 384 status: this.status,
385 message: 'HLS segment request error at URL: ' + segmentUri,
385 code: (this.status >= 500) ? 4 : 2 386 code: (this.status >= 500) ? 4 : 2
386 }; 387 };
387 player.trigger('error'); 388 player.trigger('error');
388 }
389 return; 389 return;
390 } 390 }
391 391
392 // the segment request is no longer outstanding
393 segmentXhr = null;
394
395 // stop processing if the request was aborted 392 // stop processing if the request was aborted
396 if (!this.response) { 393 if (!this.response) {
397 return; 394 return;
...@@ -423,7 +420,6 @@ var ...@@ -423,7 +420,6 @@ var
423 player.hls.mediaIndex++; 420 player.hls.mediaIndex++;
424 421
425 if (player.hls.mediaIndex === player.hls.media.segments.length) { 422 if (player.hls.mediaIndex === player.hls.media.segments.length) {
426 //TODO - Fix the endofstream //
427 mediaSource.endOfStream(); 423 mediaSource.endOfStream();
428 return; 424 return;
429 } 425 }
...@@ -436,7 +432,6 @@ var ...@@ -436,7 +432,6 @@ var
436 } else { 432 } else {
437 player.hls.media = playlist; 433 player.hls.media = playlist;
438 } 434 }
439 }
440 }; 435 };
441 startTime = +new Date(); 436 startTime = +new Date();
442 segmentXhr.send(null); 437 segmentXhr.send(null);
......
...@@ -603,8 +603,8 @@ test('segment 404 should trigger MEDIA_ERR_NETWORK', function () { ...@@ -603,8 +603,8 @@ test('segment 404 should trigger MEDIA_ERR_NETWORK', function () {
603 }); 603 });
604 604
605 equal(true, errorTriggered, 'Missing Segment error event should trigger'); 605 equal(true, errorTriggered, 'Missing Segment error event should trigger');
606 equal(2, player.error.code, 'Player error code should be set to MediaError.MEDIA_ERR_NETWORK'); 606 ok(player.hls.error.message, 'an error message is available');
607 equal('hls-missing-segment', player.error.type, 'Player error type should inform user correctly'); 607 equal(2, player.hls.error.code, 'Player error code should be set to MediaError.MEDIA_ERR_NETWORK');
608 }); 608 });
609 609
610 test('segment 500 should trigger MEDIA_ERR_ABORTED', function () { 610 test('segment 500 should trigger MEDIA_ERR_ABORTED', function () {
...@@ -634,8 +634,8 @@ test('segment 500 should trigger MEDIA_ERR_ABORTED', function () { ...@@ -634,8 +634,8 @@ test('segment 500 should trigger MEDIA_ERR_ABORTED', function () {
634 }); 634 });
635 635
636 equal(true, errorTriggered, 'Missing Segment error event should trigger'); 636 equal(true, errorTriggered, 'Missing Segment error event should trigger');
637 equal(4, player.error.code, 'Player error code should be set to MediaError.MEDIA_ERR_ABORTED'); 637 ok(player.hls.error.message, 'an error message is available');
638 equal('hls-missing-segment', player.error.type, 'Player error type should inform user correctly'); 638 equal(4, player.hls.error.code, 'Player error code should be set to MediaError.MEDIA_ERR_ABORTED');
639 }); 639 });
640 640
641 module('segment controller', { 641 module('segment controller', {
......