be8ad5db by bc-bbay

Fixing bug that started playback at 2nd segment

Bugfix and unit test
1 parent c4110efc
...@@ -666,7 +666,7 @@ videojs.Hls.prototype.drainBuffer = function(event) { ...@@ -666,7 +666,7 @@ videojs.Hls.prototype.drainBuffer = function(event) {
666 segmentOffset, 666 segmentOffset,
667 segmentBuffer = this.segmentBuffer_; 667 segmentBuffer = this.segmentBuffer_;
668 668
669 if (!segmentBuffer.length) { 669 if (!segmentBuffer.length || !this.sourceBuffer) {
670 return; 670 return;
671 } 671 }
672 672
......
...@@ -1724,6 +1724,41 @@ test('calling play() at the end of a video resets the media index', function() { ...@@ -1724,6 +1724,41 @@ test('calling play() at the end of a video resets the media index', function() {
1724 strictEqual(player.hls.mediaIndex, 0, 'index is 1 after the first segment'); 1724 strictEqual(player.hls.mediaIndex, 0, 'index is 1 after the first segment');
1725 }); 1725 });
1726 1726
1727 test('drainBuffer will not proceed with empty source buffer', function() {
1728 var oldMedia, newMedia, compareBuffer;
1729 player.src({
1730 src: 'https://example.com/encrypted-media.m3u8',
1731 type: 'application/vnd.apple.mpegurl'
1732 });
1733 openMediaSource(player);
1734
1735 oldMedia = player.hls.playlists.media;
1736 newMedia = {segments: [{
1737 key: {
1738 'retries': 5
1739 },
1740 uri: 'http://media.example.com/fileSequence52-A.ts'
1741 }, {
1742 key: {
1743 'method': 'AES-128',
1744 'uri': 'https://priv.example.com/key.php?r=53'
1745 },
1746 uri: 'http://media.example.com/fileSequence53-B.ts'
1747 }]};
1748 player.hls.playlists.media = function() {
1749 return newMedia;
1750 };
1751
1752 player.hls.sourceBuffer = undefined;
1753 compareBuffer = [{mediaIndex: 0, playlist: newMedia, offset: 0, bytes: [0,0,0]}];
1754 player.hls.segmentBuffer_ = [{mediaIndex: 0, playlist: newMedia, offset: 0, bytes: [0,0,0]}];
1755
1756 player.hls.drainBuffer();
1757 deepEqual(player.hls.segmentBuffer_,compareBuffer,'playlist remains unchanged');
1758
1759 player.hls.playlists.media = oldMedia;
1760 });
1761
1727 test('calling fetchKeys() when a new playlist is loaded will create an XHR', function() { 1762 test('calling fetchKeys() when a new playlist is loaded will create an XHR', function() {
1728 player.src({ 1763 player.src({
1729 src: 'https://example.com/encrypted-media.m3u8', 1764 src: 'https://example.com/encrypted-media.m3u8',
......