6da9fd14 by Brandon Bay

Changes from PR review; minor bug fix

1 parent 354d9449
...@@ -248,10 +248,6 @@ videojs.Hls.prototype.src = function(src) { ...@@ -248,10 +248,6 @@ videojs.Hls.prototype.src = function(src) {
248 the current time to go along with it. 248 the current time to go along with it.
249 */ 249 */
250 videojs.Hls.getMediaIndexForLive = function(selectedPlaylist) { 250 videojs.Hls.getMediaIndexForLive = function(selectedPlaylist) {
251 if (!selectedPlaylist.segments) {
252 return 0;
253 }
254
255 var tailIterator = selectedPlaylist.segments.length, 251 var tailIterator = selectedPlaylist.segments.length,
256 tailDuration = 0, 252 tailDuration = 0,
257 targetTail = (selectedPlaylist.targetDuration || 10) * 3; 253 targetTail = (selectedPlaylist.targetDuration || 10) * 3;
...@@ -291,9 +287,9 @@ videojs.Hls.prototype.play = function() { ...@@ -291,9 +287,9 @@ videojs.Hls.prototype.play = function() {
291 this.mediaIndex = 0; 287 this.mediaIndex = 0;
292 } 288 }
293 289
294 if (this.playlists.media() && !this.el().classList.contains('vjs-has-started')) { 290 if (this.playlists.media() && !this.player_.hasClass('vjs-has-started')) {
295 this.mediaIndex = videojs.Hls.getMediaIndexForLive(this.playlists.media()); 291 this.mediaIndex = videojs.Hls.getMediaIndexForLive(this.playlists.media());
296 this.setCurrentTime(this.setCurrentTimeByMediaIndex(this.playlists.media(), this.mediaIndex)); 292 this.setCurrentTime(this.getCurrentTimeByMediaIndex(this.playlists.media(), this.mediaIndex));
297 } 293 }
298 294
299 // delegate back to the Flash implementation 295 // delegate back to the Flash implementation
...@@ -990,14 +986,23 @@ videojs.Hls.getMediaIndexByTime = function(playlist, time) { ...@@ -990,14 +986,23 @@ videojs.Hls.getMediaIndexByTime = function(playlist, time) {
990 return -1; 986 return -1;
991 }; 987 };
992 988
993 videojs.Hls.prototype.setCurrentTimeByMediaIndex = function(playlist, mediaIndex) { 989 /**
990 * Determine the current time in seconds in one playlist by a media index. This
991 * function iterates through the segments of a playlist up to the specified index
992 * and then returns the time up to that point.
993 *
994 * @param playlist {object} The playlist of the segments being searched.
995 * @param mediaIndex {number} The index of the target segment in the playlist.
996 * @returns {number} The current time to that point, or 0 if none appropriate.
997 */
998 videojs.Hls.prototype.getCurrentTimeByMediaIndex = function(playlist, mediaIndex) {
994 var index, time = 0; 999 var index, time = 0;
995 1000
996 if (!playlist.segments || mediaIndex === 0) { 1001 if (!playlist.segments || mediaIndex === 0) {
997 return 0; 1002 return 0;
998 } 1003 }
999 1004
1000 for (index = 0; index < mediaIndex - 1; index++) { 1005 for (index = 0; index < mediaIndex; index++) {
1001 time += playlist.segments[index].duration; 1006 time += playlist.segments[index].duration;
1002 } 1007 }
1003 1008
......