Merge branch 'feature/basic-playback' of github.com:brightcove/videojs-contrib-h…
…ls into feature/basic-playback
Showing
2 changed files
with
60 additions
and
65 deletions
... | @@ -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 | |||
296 | // update the duration | ||
295 | if (parser.manifest.totalDuration) { | 297 | if (parser.manifest.totalDuration) { |
296 | // update the duration | ||
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; |
313 | |||
314 | // update the duration | ||
314 | if (player.hls.media.totalDuration) { | 315 | if (player.hls.media.totalDuration) { |
315 | // update the duration | ||
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,72 +370,67 @@ var | ... | @@ -370,72 +370,67 @@ 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 | segmentXhr = null; | 378 | // the segment request is no longer outstanding |
379 | fillBuffer(); | 379 | segmentXhr = null; |
380 | } else { | 380 | |
381 | player.error = { | 381 | // trigger an error if the request was not successful |
382 | type: 'hls-missing-segment', | 382 | if (this.status >= 400) { |
383 | message: 'HLS Missing Segment at index ' + player.hls.mediaIndex, | 383 | player.hls.error = { |
384 | status: this.status, | 384 | status: this.status, |
385 | code: (this.status >= 500) ? 4 : 2 | 385 | message: 'HLS segment request error at URL: ' + segmentUri, |
386 | }; | 386 | code: (this.status >= 500) ? 4 : 2 |
387 | player.trigger('error'); | 387 | }; |
388 | } | 388 | player.trigger('error'); |
389 | return; | 389 | return; |
390 | } | 390 | } |
391 | |||
392 | // the segment request is no longer outstanding | ||
393 | segmentXhr = null; | ||
394 | |||
395 | // stop processing if the request was aborted | ||
396 | if (!this.response) { | ||
397 | return; | ||
398 | } | ||
399 | 391 | ||
400 | // calculate the download bandwidth | 392 | // stop processing if the request was aborted |
401 | player.hls.segmentXhrTime = (+new Date()) - startTime; | 393 | if (!this.response) { |
402 | player.hls.bandwidth = (this.response.byteLength / player.hls.segmentXhrTime) * 8 * 1000; | 394 | return; |
395 | } | ||
403 | 396 | ||
404 | // transmux the segment data from MP2T to FLV | 397 | // calculate the download bandwidth |
405 | segmentParser.parseSegmentBinaryData(new Uint8Array(this.response)); | 398 | player.hls.segmentXhrTime = (+new Date()) - startTime; |
399 | player.hls.bandwidth = (this.response.byteLength / player.hls.segmentXhrTime) * 8 * 1000; | ||
406 | 400 | ||
407 | // handle intra-segment seeking, if requested // | 401 | // transmux the segment data from MP2T to FLV |
408 | if (offset !== undefined && typeof offset === "number") { | 402 | segmentParser.parseSegmentBinaryData(new Uint8Array(this.response)); |
409 | player.el().querySelector('.vjs-tech').vjs_setProperty('lastSeekedTime', player.hls.getPtsByTime(segmentParser,offset)/1000); | 403 | |
410 | for (tagIndex = 0; tagIndex < segmentParser.getTags().length; tagIndex++) { | 404 | // handle intra-segment seeking, if requested // |
411 | if (segmentParser.getTags()[tagIndex].pts > offset) { | 405 | if (offset !== undefined && typeof offset === "number") { |
412 | break; | 406 | player.el().querySelector('.vjs-tech').vjs_setProperty('lastSeekedTime', player.hls.getPtsByTime(segmentParser,offset)/1000); |
413 | } | 407 | for (tagIndex = 0; tagIndex < segmentParser.getTags().length; tagIndex++) { |
414 | // we're seeking past this tag, so ignore it | 408 | if (segmentParser.getTags()[tagIndex].pts > offset) { |
415 | segmentParser.getNextTag(); | 409 | break; |
416 | } | 410 | } |
411 | // we're seeking past this tag, so ignore it | ||
412 | segmentParser.getNextTag(); | ||
417 | } | 413 | } |
414 | } | ||
418 | 415 | ||
419 | while (segmentParser.tagsAvailable()) { | 416 | while (segmentParser.tagsAvailable()) { |
420 | player.hls.sourceBuffer.appendBuffer(segmentParser.getNextTag().bytes, player); | 417 | player.hls.sourceBuffer.appendBuffer(segmentParser.getNextTag().bytes, player); |
421 | } | 418 | } |
422 | 419 | ||
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 // | 423 | mediaSource.endOfStream(); |
427 | mediaSource.endOfStream(); | 424 | return; |
428 | return; | 425 | } |
429 | } | ||
430 | 426 | ||
431 | // figure out what stream the next segment should be downloaded from | 427 | // figure out what stream the next segment should be downloaded from |
432 | // with the updated bandwidth information | 428 | // with the updated bandwidth information |
433 | playlist = player.hls.selectPlaylist(); | 429 | playlist = player.hls.selectPlaylist(); |
434 | if (!playlist.segments) { | 430 | if (!playlist.segments) { |
435 | downloadPlaylist(resolveUrl(srcUrl, playlist.uri)); | 431 | downloadPlaylist(resolveUrl(srcUrl, playlist.uri)); |
436 | } else { | 432 | } else { |
437 | player.hls.media = playlist; | 433 | player.hls.media = playlist; |
438 | } | ||
439 | } | 434 | } |
440 | }; | 435 | }; |
441 | startTime = +new Date(); | 436 | startTime = +new Date(); | ... | ... |
... | @@ -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', { | ... | ... |
-
Please register or sign in to post a comment