From 0448c9942d4768800cdeae5c8450e70eac9bfd07 Mon Sep 17 00:00:00 2001 From: Waheed Ahmed Date: Wed, 3 Sep 2014 19:23:41 +0500 Subject: [PATCH] Fixed video not playing after changing speed to anything other than 1. BLD-1221 --- .../js/spec/video/video_player_spec.js | 2 +- .../xmodule/js/src/video/03_video_player.js | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js b/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js index 785f0d9183..67c75867a0 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/video_player_spec.js @@ -496,7 +496,7 @@ function (VideoPlayer) { state.speed = '2.0'; state.videoPlayer.onPlay(); expect(state.videoPlayer.setPlaybackRate) - .toHaveBeenCalledWith('2.0'); + .toHaveBeenCalledWith('2.0', true); state.videoPlayer.onPlay(); expect(state.videoPlayer.setPlaybackRate.calls.length) .toEqual(1); diff --git a/common/lib/xmodule/xmodule/js/src/video/03_video_player.js b/common/lib/xmodule/xmodule/js/src/video/03_video_player.js index ef3d7fcd60..6a3834855c 100644 --- a/common/lib/xmodule/xmodule/js/src/video/03_video_player.js +++ b/common/lib/xmodule/xmodule/js/src/video/03_video_player.js @@ -96,7 +96,7 @@ function (HTML5Video, Resizer) { $(window).on('unload', state.saveState); if (!state.isFlashMode() && state.speed != '1.0') { - state.videoPlayer.setPlaybackRate(state.speed); + state.videoPlayer.setPlaybackRate(state.speed, true); } }); @@ -351,18 +351,17 @@ function (HTML5Video, Resizer) { } } - function setPlaybackRate(newSpeed) { + function setPlaybackRate(newSpeed, useCueVideoById) { var duration = this.videoPlayer.duration(), time = this.videoPlayer.currentTime, methodName, youtubeId; + // If useCueVideoById is true it will reload video again. + // Used useCueVideoById to fix the issue video not playing if we change + // the speed before playing the video. if ( - this.isHtml5Mode() && - !( - this.browserIsFirefox && - newSpeed === '1.0' && - this.isYoutubeType() - ) + this.isHtml5Mode() && !(this.browserIsFirefox && + (useCueVideoById || newSpeed === '1.0') && this.isYoutubeType()) ) { this.videoPlayer.player.setPlaybackRate(newSpeed); } else { @@ -385,7 +384,10 @@ function (HTML5Video, Resizer) { // is in a PAUSED state. // // Why? This is how the YouTube API is implemented. - this.videoPlayer.updatePlayTime(time); + // sjson.search() only works if time is defined. + if (!_.isUndefined(time)) { + this.videoPlayer.updatePlayTime(time); + } if (time > 0 && this.isFlashMode()) { this.videoPlayer.seekTo(time); this.trigger(