From 4b5f77aa55ab4e1718a1e0c346799453cae97d15 Mon Sep 17 00:00:00 2001 From: Valera Rozuvan Date: Fri, 16 Aug 2013 14:06:42 +0300 Subject: [PATCH] Added back old method of getting caption position for Flash video playback. Because with speed changing the time also changes for Flash playback, a different way to calculate the current time is needed than for HTML5 playback. I have added conditions for Flash and HTML5 video, and put old method of calculating time for Flash. I have tested it on the YouTube video ZwkTiUPN0mg. Both HTML5 mode and Flash mode have proper video-captions syncing with this fix. NOTE: to view YouTube video in Flash mode you either have to use an old browser (ex. Firefox version 18) or hard code in source that state.currentPlayerMode = 'flash' (in function _setPlayerMode(), file 01_initialize.js). --- .../xmodule/js/src/video/09_video_caption.js | 51 ++++++++++++++++--- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/video/09_video_caption.js b/common/lib/xmodule/xmodule/js/src/video/09_video_caption.js index 5ec111219a..a34f33ba4c 100644 --- a/common/lib/xmodule/xmodule/js/src/video/09_video_caption.js +++ b/common/lib/xmodule/xmodule/js/src/video/09_video_caption.js @@ -312,15 +312,34 @@ function () { var newIndex; if (this.videoCaption.loaded) { - time = Math.round(parseInt(time, 10) * 1000); + // Current mode === 'flash' can only be for YouTube videos. So, we + // don't have to also check for videoType === 'youtube'. + if (this.currentPlayerMode === 'flash') { + // Total play time changes with speed change. Also there is + // a 250 ms delay we have to take into account. + time = Math.round( + Time.convert(time, this.speed, '1.0') * 1000 + 250 + ); + } else { + // Total play time remains constant when speed changes. + time = Math.round(parseInt(time, 10) * 1000); + } + newIndex = this.videoCaption.search(time); - if (newIndex !== void 0 && this.videoCaption.currentIndex !== newIndex) { + if ( + newIndex !== void 0 && + this.videoCaption.currentIndex !== newIndex + ) { if (this.videoCaption.currentIndex) { - this.videoCaption.subtitlesEl.find('li.current').removeClass('current'); + this.videoCaption.subtitlesEl + .find('li.current') + .removeClass('current'); } - this.videoCaption.subtitlesEl.find("li[data-index='" + newIndex + "']").addClass('current'); + this.videoCaption.subtitlesEl + .find("li[data-index='" + newIndex + "']") + .addClass('current'); this.videoCaption.currentIndex = newIndex; @@ -333,9 +352,29 @@ function () { var time; event.preventDefault(); - time = parseInt($(event.target).data('start'), 10)/1000; - this.trigger('videoPlayer.onCaptionSeek', {'type': 'onCaptionSeek', 'time': time}); + // Current mode === 'flash' can only be for YouTube videos. So, we + // don't have to also check for videoType === 'youtube'. + if (this.currentPlayerMode === 'flash') { + // Total play time changes with speed change. Also there is + // a 250 ms delay we have to take into account. + time = Math.round( + Time.convert( + $(event.target).data('start'), '1.0', this.speed + ) / 1000 + ); + } else { + // Total play time remains constant when speed changes. + time = parseInt($(event.target).data('start'), 10)/1000; + } + + this.trigger( + 'videoPlayer.onCaptionSeek', + { + 'type': 'onCaptionSeek', + 'time': time + } + ); } function calculateOffset(element) {