Commit c667c013 by Valera Rozuvan

Fix start-time functionality in the video player.

When there is a start-time:

Initially, the video starts playing from the start-time.
Whenever the player resets for any reason (such as reaching
the end of the video), it will reset to start-time instead of 00:00:00.
It should not be the case that any time the user presses play, it
start playing from start-time.

BLD-659.
parent 663671ec
...@@ -221,7 +221,7 @@ ...@@ -221,7 +221,7 @@
expect(state.videoPlayer.play).toHaveBeenCalled(); expect(state.videoPlayer.play).toHaveBeenCalled();
}); });
it('when cued, onEnded resets start and end time only the second time', function () { it('even when cued, onEnded does not resets start and end time', function () {
state.videoPlayer.skipOnEndedStartEndReset = true; state.videoPlayer.skipOnEndedStartEndReset = true;
state.videoPlayer.onEnded(); state.videoPlayer.onEnded();
expect(state.videoPlayer.startTime).toBe(10); expect(state.videoPlayer.startTime).toBe(10);
...@@ -229,8 +229,8 @@ ...@@ -229,8 +229,8 @@
state.videoPlayer.skipOnEndedStartEndReset = undefined; state.videoPlayer.skipOnEndedStartEndReset = undefined;
state.videoPlayer.onEnded(); state.videoPlayer.onEnded();
expect(state.videoPlayer.startTime).toBe(0); expect(state.videoPlayer.startTime).toBe(10);
expect(state.videoPlayer.endTime).toBe(null); expect(state.videoPlayer.endTime).toBe(30);
}); });
}); });
......
...@@ -562,6 +562,7 @@ function (VideoPlayer) { ...@@ -562,6 +562,7 @@ function (VideoPlayer) {
runs(function () { runs(function () {
var htmlStr; var htmlStr;
state.videoPlayer.goToStartTime = false;
state.videoPlayer.updatePlayTime(60); state.videoPlayer.updatePlayTime(60);
htmlStr = $('.vidtime').html(); htmlStr = $('.vidtime').html();
...@@ -589,6 +590,7 @@ function (VideoPlayer) { ...@@ -589,6 +590,7 @@ function (VideoPlayer) {
}, 'Video is fully loaded.', WAIT_TIMEOUT); }, 'Video is fully loaded.', WAIT_TIMEOUT);
runs(function () { runs(function () {
state.videoPlayer.goToStartTime = false;
state.videoPlayer.updatePlayTime(60); state.videoPlayer.updatePlayTime(60);
expect(state.videoCaption.updatePlayTime) expect(state.videoCaption.updatePlayTime)
...@@ -606,6 +608,7 @@ function (VideoPlayer) { ...@@ -606,6 +608,7 @@ function (VideoPlayer) {
}, 'Video is fully loaded.', WAIT_TIMEOUT); }, 'Video is fully loaded.', WAIT_TIMEOUT);
runs(function () { runs(function () {
state.videoPlayer.goToStartTime = false;
state.videoPlayer.updatePlayTime(60); state.videoPlayer.updatePlayTime(60);
expect(state.videoProgressSlider.updatePlayTime) expect(state.videoProgressSlider.updatePlayTime)
...@@ -677,35 +680,39 @@ function (VideoPlayer) { ...@@ -677,35 +680,39 @@ function (VideoPlayer) {
describe('updatePlayTime with invalid endTime', function () { describe('updatePlayTime with invalid endTime', function () {
beforeEach(function () { beforeEach(function () {
state = jasmine.initializePlayer( state = {
{ videoPlayer: {
end: 100000 duration: function () {
} // The video will be 60 seconds long.
); return 60;
},
state.videoEl = $('video, iframe'); goToStartTime: true,
startTime: undefined,
spyOn(state.videoPlayer, 'updatePlayTime').andCallThrough(); endTime: undefined,
player: {
seekTo: function () {}
}
},
config: {
savedVideoPosition: 0,
startTime: 0,
// We are setting the end-time to 10000 seconds. The
// video will be less than this, the code will reset
// the end time to `null` - i.e. to the end of the video.
// This is the expected behavior we will test for.
endTime: 10000
},
currentPlayerMode: 'html5',
trigger: function () {},
browserIsFirefox: false
};
}); });
it('invalid endTime is reset to null', function () { it('invalid endTime is reset to null', function () {
var duration; VideoPlayer.prototype.updatePlayTime.call(state, 0);
state.videoPlayer.updatePlayTime.reset(); expect(state.videoPlayer.endTime).toBe(null);
state.videoPlayer.play();
waitsFor(
function () {
return state.videoPlayer.isPlaying() &&
state.videoPlayer.initialSeekToStartTime === false;
},
'updatePlayTime was invoked and duration is set',
WAIT_TIMEOUT
);
runs(function () {
expect(state.videoPlayer.endTime).toBe(null);
});
}); });
}); });
......
...@@ -180,6 +180,10 @@ function () { ...@@ -180,6 +180,10 @@ function () {
function onSlide(event, ui) { function onSlide(event, ui) {
this.videoProgressSlider.frozen = true; this.videoProgressSlider.frozen = true;
// Remember the seek to value so that we don't repeat ourselves on the
// 'stop' slider event.
this.videoProgressSlider.lastSeekValue = ui.value;
this.trigger( this.trigger(
'videoPlayer.onSlideSeek', 'videoPlayer.onSlideSeek',
{'type': 'onSlideSeek', 'time': ui.value} {'type': 'onSlideSeek', 'time': ui.value}
...@@ -196,10 +200,16 @@ function () { ...@@ -196,10 +200,16 @@ function () {
this.videoProgressSlider.frozen = true; this.videoProgressSlider.frozen = true;
this.trigger( // Only perform a seek if we haven't made a seek for the new slider value.
'videoPlayer.onSlideSeek', // This is necessary so that if the user only clicks on the slider, without
{'type': 'onSlideSeek', 'time': ui.value} // dragging it, then only one seek is made, even when a 'slide' and a 'stop'
); // events are triggered on the slider.
if (this.videoProgressSlider.lastSeekValue !== ui.value) {
this.trigger(
'videoPlayer.onSlideSeek',
{'type': 'onSlideSeek', 'time': ui.value}
);
}
// ARIA // ARIA
this.videoProgressSlider.handle.attr( this.videoProgressSlider.handle.attr(
...@@ -216,8 +226,8 @@ function () { ...@@ -216,8 +226,8 @@ function () {
duration = Math.floor(params.duration); duration = Math.floor(params.duration);
if ( if (
(this.videoProgressSlider.slider) && this.videoProgressSlider.slider &&
(!this.videoProgressSlider.frozen) !this.videoProgressSlider.frozen
) { ) {
this.videoProgressSlider.slider this.videoProgressSlider.slider
.slider('option', 'max', duration) .slider('option', 'max', duration)
......
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