@@ -420,11 +420,10 @@ function addControlFunctions(AblePlayer) {
420420 // 'fullscreen' - a change has been triggered by full screen toggle
421421 // 'playpause' - a change triggered by either a 'play' or 'pause' event
422422
423- // NOTE: context is not currently supported.
424- // The steps in this function have too many complex interdependencies
425- // The gains in efficiency are offset by the possibility of introducing bugs
426- // For now, executing everything
427- context = 'init' ;
423+ // Normalize context to a known value.
424+ if ( [ 'init' , 'timeline' , 'captions' , 'descriptions' , 'transcript' , 'fullscreen' , 'playpause' ] . indexOf ( context ) === - 1 ) {
425+ context = 'init' ;
426+ }
428427
429428 // duration and elapsed are passed from callback functions of Vimeo API events
430429 // duration is expressed as sss.xxx
@@ -442,7 +441,7 @@ function addControlFunctions(AblePlayer) {
442441 if ( context === 'timeline' || context === 'init' ) {
443442 // Update timeline controls.
444443 var lastChapterIndex , displayElapsed , updateLive , widthUsed ,
445- leftControls , rightControls , seekbarWidth , buffered ;
444+ leftControls , rightControls , seekbarWidth , buffered , mediaDuration ;
446445 // all timeline-related functionality requires duration
447446 if ( typeof this . duration === 'undefined' ) {
448447 // wait until duration is known before proceeding with refresh
@@ -541,16 +540,17 @@ function addControlFunctions(AblePlayer) {
541540 // TODO: Currently only using the first HTML5 buffered interval,
542541 // but this fails sometimes when buffering is split into two or more intervals.
543542 if ( this . player === 'html5' && this . media . buffered . length > 0 ) {
543+ mediaDuration = ( typeof duration !== 'undefined' && ! isNaN ( duration ) && duration > 0 ) ? duration : this . duration ;
544544 buffered = this . media . buffered . end ( 0 ) ;
545545 if ( this . useChapterTimes ) {
546546 if ( buffered > this . chapterDuration ) {
547547 buffered = this . chapterDuration ;
548548 }
549- if ( this . seekBar ) {
549+ if ( this . seekBar && this . chapterDuration > 0 ) {
550550 this . seekBar . setBuffered ( buffered / this . chapterDuration ) ;
551551 }
552- } else if ( this . seekBar && ! isNaN ( buffered ) ) {
553- this . seekBar . setBuffered ( buffered / duration ) ;
552+ } else if ( this . seekBar && ! isNaN ( buffered ) && ! isNaN ( mediaDuration ) && mediaDuration > 0 ) {
553+ this . seekBar . setBuffered ( buffered / mediaDuration ) ;
554554 }
555555 } else if ( this . player === 'youtube' && this . seekBar && this . youTubePlayerReady ) {
556556 this . seekBar . setBuffered ( this . youTubePlayer . getVideoLoadedFraction ( ) ) ;
0 commit comments