Commit b4c8e63f by Valera Rozuvan

Merge pull request #2744 from edx/valera/move_slider_and_vcr_to_start_time_2

Show start time or starting position on slider and VCR
parents 01def12d b85130bb
...@@ -5,6 +5,8 @@ These are notable changes in edx-platform. This is a rolling list of changes, ...@@ -5,6 +5,8 @@ These are notable changes in edx-platform. This is a rolling list of changes,
in roughly chronological order, most recent first. Add your entries at or near in roughly chronological order, most recent first. Add your entries at or near
the top. Include a label indicating the component affected. the top. Include a label indicating the component affected.
Blades: Show start time or starting position on slider and VCR. BLD-823.
Common: Upgraded CodeMirror to 3.21.0 with an accessibility patch applied. Common: Upgraded CodeMirror to 3.21.0 with an accessibility patch applied.
LMS-1802 LMS-1802
......
...@@ -253,8 +253,8 @@ ...@@ -253,8 +253,8 @@
return state; return state;
}; };
jasmine.initializePlayerYouTube = function () { jasmine.initializePlayerYouTube = function (params) {
// "video.html" contains HTML template for a YouTube video. // "video.html" contains HTML template for a YouTube video.
return jasmine.initializePlayer('video.html'); return jasmine.initializePlayer('video.html', params);
}; };
}).call(this, window.jQuery); }).call(this, window.jQuery);
...@@ -538,10 +538,8 @@ function (VideoPlayer) { ...@@ -538,10 +538,8 @@ function (VideoPlayer) {
describe('updatePlayTime', function () { describe('updatePlayTime', function () {
beforeEach(function () { beforeEach(function () {
state = jasmine.initializePlayer(); state = jasmine.initializePlayerYouTube();
state.videoEl = $('video, iframe'); state.videoEl = $('video, iframe');
spyOn(state.videoCaption, 'updatePlayTime').andCallThrough(); spyOn(state.videoCaption, 'updatePlayTime').andCallThrough();
spyOn(state.videoProgressSlider, 'updatePlayTime').andCallThrough(); spyOn(state.videoProgressSlider, 'updatePlayTime').andCallThrough();
}); });
...@@ -560,27 +558,10 @@ function (VideoPlayer) { ...@@ -560,27 +558,10 @@ function (VideoPlayer) {
}, 'Video is fully loaded.', WAIT_TIMEOUT); }, 'Video is fully loaded.', WAIT_TIMEOUT);
runs(function () { runs(function () {
var htmlStr;
state.videoPlayer.goToStartTime = false; state.videoPlayer.goToStartTime = false;
state.videoPlayer.updatePlayTime(60); state.videoPlayer.updatePlayTime(60);
htmlStr = $('.vidtime').html(); expect($('.vidtime')).toHaveHtml('1:00 / 1:00');
// We resort to this trickery because Firefox and Chrome
// round the total time a bit differently.
if (
htmlStr.match('1:00 / 1:01') ||
htmlStr.match('1:00 / 1:00')
) {
expect(true).toBe(true);
} else {
expect(true).toBe(false);
}
// The below test has been replaced by above trickery:
//
// expect($('.vidtime')).toHaveHtml('1:00 / 1:01');
}); });
}); });
...@@ -691,7 +672,9 @@ function (VideoPlayer) { ...@@ -691,7 +672,9 @@ function (VideoPlayer) {
endTime: undefined, endTime: undefined,
player: { player: {
seekTo: function () {} seekTo: function () {}
} },
figureOutStartEndTime: jasmine.createSpy(),
figureOutStartingTime: jasmine.createSpy().andReturn(0)
}, },
config: { config: {
savedVideoPosition: 0, savedVideoPosition: 0,
...@@ -712,6 +695,11 @@ function (VideoPlayer) { ...@@ -712,6 +695,11 @@ function (VideoPlayer) {
it('invalid endTime is reset to null', function () { it('invalid endTime is reset to null', function () {
VideoPlayer.prototype.updatePlayTime.call(state, 0); VideoPlayer.prototype.updatePlayTime.call(state, 0);
expect(state.videoPlayer.figureOutStartingTime).toHaveBeenCalled();
VideoPlayer.prototype.figureOutStartEndTime.call(state, 60);
VideoPlayer.prototype.figureOutStartingTime.call(state, 60);
expect(state.videoPlayer.endTime).toBe(null); expect(state.videoPlayer.endTime).toBe(null);
}); });
}); });
......
...@@ -35,6 +35,8 @@ function (HTML5Video, Resizer) { ...@@ -35,6 +35,8 @@ function (HTML5Video, Resizer) {
play: play, play: play,
setPlaybackRate: setPlaybackRate, setPlaybackRate: setPlaybackRate,
update: update, update: update,
figureOutStartEndTime: figureOutStartEndTime,
figureOutStartingTime: figureOutStartingTime,
updatePlayTime: updatePlayTime updatePlayTime: updatePlayTime
}; };
...@@ -62,7 +64,7 @@ function (HTML5Video, Resizer) { ...@@ -62,7 +64,7 @@ function (HTML5Video, Resizer) {
// via the 'state' object. Much easier to work this way - you don't // via the 'state' object. Much easier to work this way - you don't
// have to do repeated jQuery element selects. // have to do repeated jQuery element selects.
function _initialize(state) { function _initialize(state) {
var youTubeId, player, duration; var youTubeId, player;
// The function is called just once to apply pre-defined configurations // The function is called just once to apply pre-defined configurations
// by student before video starts playing. Waits until the video's // by student before video starts playing. Waits until the video's
...@@ -134,22 +136,7 @@ function (HTML5Video, Resizer) { ...@@ -134,22 +136,7 @@ function (HTML5Video, Resizer) {
_resize(state, videoWidth, videoHeight); _resize(state, videoWidth, videoHeight);
duration = state.videoPlayer.duration(); _updateVcrAndRegion(state);
state.trigger(
'videoControl.updateVcrVidTime',
{
time: 0,
duration: duration
}
);
state.trigger(
'videoProgressSlider.updateStartEndTimeRegion',
{
duration: duration
}
);
}, false); }, false);
} else { // if (state.videoType === 'youtube') { } else { // if (state.videoType === 'youtube') {
...@@ -200,22 +187,34 @@ function (HTML5Video, Resizer) { ...@@ -200,22 +187,34 @@ function (HTML5Video, Resizer) {
} }
function _updateVcrAndRegion(state) { function _updateVcrAndRegion(state) {
var duration = state.videoPlayer.duration(); var duration = state.videoPlayer.duration(),
time;
time = state.videoPlayer.figureOutStartingTime(duration);
// Update the VCR.
state.trigger( state.trigger(
'videoControl.updateVcrVidTime', 'videoControl.updateVcrVidTime',
{ {
time: 0, time: time,
duration: duration duration: duration
} }
); );
// Update the time slider.
state.trigger( state.trigger(
'videoProgressSlider.updateStartEndTimeRegion', 'videoProgressSlider.updateStartEndTimeRegion',
{ {
duration: duration duration: duration
} }
); );
state.trigger(
'videoProgressSlider.updatePlayTime',
{
time: time,
duration: duration
}
);
} }
function _resize(state, videoWidth, videoHeight) { function _resize(state, videoWidth, videoHeight) {
...@@ -642,62 +641,46 @@ function (HTML5Video, Resizer) { ...@@ -642,62 +641,46 @@ function (HTML5Video, Resizer) {
} }
} }
function updatePlayTime(time) { function figureOutStartEndTime(duration) {
var videoPlayer = this.videoPlayer, var videoPlayer = this.videoPlayer;
duration = this.videoPlayer.duration(),
savedVideoPosition = this.config.savedVideoPosition,
youTubeId, startTime, endTime;
if (duration > 0 && videoPlayer.goToStartTime) { videoPlayer.startTime = this.config.startTime;
videoPlayer.goToStartTime = false; if (videoPlayer.startTime >= duration) {
videoPlayer.startTime = 0;
} else if (this.currentPlayerMode === 'flash') {
videoPlayer.startTime /= Number(this.speed);
}
videoPlayer.startTime = this.config.startTime; videoPlayer.endTime = this.config.endTime;
if (videoPlayer.startTime >= duration) { if (
videoPlayer.startTime = 0; videoPlayer.endTime <= videoPlayer.startTime ||
} else if (this.currentPlayerMode === 'flash') { videoPlayer.endTime >= duration
videoPlayer.startTime /= Number(this.speed); ) {
} videoPlayer.stopAtEndTime = false;
videoPlayer.endTime = null;
} else if (this.currentPlayerMode === 'flash') {
videoPlayer.endTime /= Number(this.speed);
}
}
videoPlayer.endTime = this.config.endTime; function figureOutStartingTime(duration) {
if ( var savedVideoPosition = this.config.savedVideoPosition,
videoPlayer.endTime <= videoPlayer.startTime ||
videoPlayer.endTime >= duration
) {
videoPlayer.stopAtEndTime = false;
videoPlayer.endTime = null;
} else if (this.currentPlayerMode === 'flash') {
videoPlayer.endTime /= Number(this.speed);
}
this.trigger( // Default starting time is 0. This is the case when
'videoProgressSlider.updateStartEndTimeRegion', // there is not start-time, no previously saved position,
{ // or one (or both) of those values is incorrect.
duration: duration time = 0,
}
);
startTime = videoPlayer.startTime; startTime, endTime;
endTime = videoPlayer.endTime;
if (startTime) { this.videoPlayer.figureOutStartEndTime(duration);
if (
startTime < savedVideoPosition &&
(endTime > savedVideoPosition || endTime === null) &&
// We do not want to jump to the end of the video. startTime = this.videoPlayer.startTime;
// We subtract 1 from the duration for a 1 second endTime = this.videoPlayer.endTime;
// safety net.
savedVideoPosition < duration - 1
) {
time = savedVideoPosition;
// When the video finishes playing, we will start from the if (startTime > 0) {
// start-time, rather than from the remembered position if (
this.config.savedVideoPosition = 0; startTime < savedVideoPosition &&
} else {
time = startTime;
}
} else if (
(endTime > savedVideoPosition || endTime === null) && (endTime > savedVideoPosition || endTime === null) &&
// We do not want to jump to the end of the video. // We do not want to jump to the end of the video.
...@@ -706,13 +689,47 @@ function (HTML5Video, Resizer) { ...@@ -706,13 +689,47 @@ function (HTML5Video, Resizer) {
savedVideoPosition < duration - 1 savedVideoPosition < duration - 1
) { ) {
time = savedVideoPosition; time = savedVideoPosition;
// When the video finishes playing, we will start from the
// start-time, rather than from the remembered position
this.config.savedVideoPosition = 0;
} else { } else {
time = 0; time = startTime;
} }
} else if (
savedVideoPosition > 0 &&
(endTime > savedVideoPosition || endTime === null) &&
// We do not want to jump to the end of the video.
// We subtract 1 from the duration for a 1 second
// safety net.
savedVideoPosition < duration - 1
) {
time = savedVideoPosition;
}
return time;
}
function updatePlayTime(time) {
var videoPlayer = this.videoPlayer,
duration = this.videoPlayer.duration(),
youTubeId;
if (duration > 0 && videoPlayer.goToStartTime) {
videoPlayer.goToStartTime = false;
// The duration might have changed. Update the start-end time region to
// reflect this fact.
this.trigger(
'videoProgressSlider.updateStartEndTimeRegion',
{
duration: duration
}
);
time = videoPlayer.figureOutStartingTime(duration);
// When the video finishes playing, we will start from the
// start-time, or from the beginning (rather than from the remembered
// position).
this.config.savedVideoPosition = 0;
if (time > 0) { if (time > 0) {
// After a bug came up (BLD-708: "In Firefox YouTube video with // After a bug came up (BLD-708: "In Firefox YouTube video with
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment