f51b1039 by Jernej Fijačko Committed by David LaPalomento

Fix possible seek issues in content where segment preciseDuration is shorter tha…

…n playlist segment duration
1 parent af92753d
...@@ -812,6 +812,8 @@ videojs.Hls.prototype.drainBuffer = function(event) { ...@@ -812,6 +812,8 @@ videojs.Hls.prototype.drainBuffer = function(event) {
812 decrypter, 812 decrypter,
813 segIv, 813 segIv,
814 ptsTime, 814 ptsTime,
815 tagPts,
816 tagIndex,
815 segmentOffset = 0, 817 segmentOffset = 0,
816 segmentBuffer = this.segmentBuffer_; 818 segmentBuffer = this.segmentBuffer_;
817 819
...@@ -912,14 +914,23 @@ videojs.Hls.prototype.drainBuffer = function(event) { ...@@ -912,14 +914,23 @@ videojs.Hls.prototype.drainBuffer = function(event) {
912 if (typeof offset === 'number') { 914 if (typeof offset === 'number') {
913 ptsTime = offset - segmentOffset + tags[0].pts; 915 ptsTime = offset - segmentOffset + tags[0].pts;
914 916
915 while (tags[i].pts < ptsTime) { 917 tagPts = tags[i].pts;
918 tagIndex = i;
919 while (tagPts < ptsTime) {
916 i++; 920 i++;
921 if (tags[i] !== undefined) {
922 tagPts = tags[i].pts;
923 tagIndex = i;
924 }
925 else {
926 break;
927 }
917 } 928 }
918 929
919 // tell the SWF where we will be seeking to 930 // tell the SWF where we will be seeking to
920 this.el().vjs_setProperty('currentTime', (tags[i].pts - tags[0].pts + segmentOffset) * 0.001); 931 this.el().vjs_setProperty('currentTime', (tagPts - tags[0].pts + segmentOffset) * 0.001);
921 932
922 tags = tags.slice(i); 933 tags = tags.slice(tagIndex);
923 934
924 this.lastSeekedTime_ = null; 935 this.lastSeekedTime_ = null;
925 } 936 }
...@@ -1148,14 +1159,15 @@ videojs.Hls.getMediaIndexByTime = function() { ...@@ -1148,14 +1159,15 @@ videojs.Hls.getMediaIndexByTime = function() {
1148 * @returns {number} The current time to that point, or 0 if none appropriate. 1159 * @returns {number} The current time to that point, or 0 if none appropriate.
1149 */ 1160 */
1150 videojs.Hls.prototype.getCurrentTimeByMediaIndex_ = function(playlist, mediaIndex) { 1161 videojs.Hls.prototype.getCurrentTimeByMediaIndex_ = function(playlist, mediaIndex) {
1151 var index, time = 0; 1162 var index, time = 0, segment;
1152 1163
1153 if (!playlist.segments || mediaIndex === 0) { 1164 if (!playlist.segments || mediaIndex === 0) {
1154 return 0; 1165 return 0;
1155 } 1166 }
1156 1167
1157 for (index = 0; index < mediaIndex; index++) { 1168 for (index = 0; index < mediaIndex; index++) {
1158 time += playlist.segments[index].duration; 1169 segment = playlist.segments[index];
1170 time += segment.preciseDuration || segment.duration || playlist.targetDuration || 0;
1159 } 1171 }
1160 1172
1161 return time; 1173 return time;
......