1639b663 by Tom Johnson

Add loadedmanifest handler for duration determination

1 parent 72b55580
...@@ -207,9 +207,10 @@ var ...@@ -207,9 +207,10 @@ var
207 i, 207 i,
208 segment; 208 segment;
209 209
210 if (!playlist.segments) { 210 if (!playlist || !playlist.segments) {
211 return 0; 211 return 0;
212 } 212 }
213
213 i = playlist.segments.length; 214 i = playlist.segments.length;
214 215
215 // if present, use the duration specified in the playlist 216 // if present, use the duration specified in the playlist
...@@ -292,7 +293,8 @@ var ...@@ -292,7 +293,8 @@ var
292 segmentXhr, 293 segmentXhr,
293 loadedPlaylist, 294 loadedPlaylist,
294 fillBuffer, 295 fillBuffer,
295 updateCurrentPlaylist; 296 updateCurrentPlaylist,
297 updateDuration;
296 298
297 // if the video element supports HLS natively, do nothing 299 // if the video element supports HLS natively, do nothing
298 if (videojs.hls.supportsNativeHls) { 300 if (videojs.hls.supportsNativeHls) {
...@@ -366,6 +368,10 @@ var ...@@ -366,6 +368,10 @@ var
366 return 1; // HAVE_METADATA 368 return 1; // HAVE_METADATA
367 }; 369 };
368 370
371 player.on('loadedmanifest', function() {
372 updateDuration();
373 });
374
369 player.on('seeking', function() { 375 player.on('seeking', function() {
370 var currentTime = player.currentTime(); 376 var currentTime = player.currentTime();
371 player.hls.mediaIndex = getMediaIndexByTime(player.hls.media, currentTime); 377 player.hls.mediaIndex = getMediaIndexByTime(player.hls.media, currentTime);
...@@ -381,6 +387,20 @@ var ...@@ -381,6 +387,20 @@ var
381 }); 387 });
382 388
383 /** 389 /**
390 * Update the player duration
391 */
392 updateDuration = function() {
393 // update the duration
394 player.duration(totalDuration(player.hls.media));
395 // tell the flash tech of the new duration
396 if(player.el().querySelector('.vjs-tech').id === 'video_flash_api') {
397 player.el().querySelector('.vjs-tech').vjs_setProperty('duration', player.duration());
398 }
399 // manually fire the duration change
400 player.trigger('durationchange');
401 };
402
403 /**
384 * Determine whether the current media playlist should be changed 404 * Determine whether the current media playlist should be changed
385 * and trigger a switch if necessary. If a sufficiently fresh 405 * and trigger a switch if necessary. If a sufficiently fresh
386 * version of the target playlist is available, the switch will take 406 * version of the target playlist is available, the switch will take
...@@ -406,14 +426,7 @@ var ...@@ -406,14 +426,7 @@ var
406 playlist); 426 playlist);
407 player.hls.media = playlist; 427 player.hls.media = playlist;
408 428
409 // update the duration 429 updateDuration();
410 player.duration(totalDuration(player.hls.media));
411 // tell the flash tech of the new duration
412 if(player.el().querySelector('.vjs-tech').id === 'video_flash_api') {
413 player.el().querySelector('.vjs-tech').vjs_setProperty('duration', player.duration());
414 }
415 // manually fire the duration change
416 player.trigger('durationchange');
417 } 430 }
418 }; 431 };
419 432
......