From d0fbd502fb8f1ca0cf907e58ea167bfaf992f94f Mon Sep 17 00:00:00 2001 From: Valera Rozuvan Date: Fri, 18 Oct 2013 12:09:17 +0300 Subject: [PATCH] Initial commit for feature BLD-391: Add arrows to the interface for start/end times. If end time is specified (which means that there is also a start time), we add an extra DOM element to the slider that will show the are in time between start time and end time. Unfortunately, this visual aid will become available ony after start of playback. This is because until then we don't know the length of the video. --- .../xmodule/js/src/video/01_initialize.js | 30 ++++ .../xmodule/js/src/video/02_html5_video.js | 16 +- .../xmodule/js/src/video/03_video_player.js | 20 +-- .../js/src/video/06_video_progress_slider.js | 144 +++++++++++++----- 4 files changed, 149 insertions(+), 61 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/video/01_initialize.js b/common/lib/xmodule/xmodule/js/src/video/01_initialize.js index 67046ccc11..7df3131793 100644 --- a/common/lib/xmodule/xmodule/js/src/video/01_initialize.js +++ b/common/lib/xmodule/xmodule/js/src/video/01_initialize.js @@ -75,6 +75,8 @@ function (VideoPlayer) { state.parseYoutubeStreams = _.bind(parseYoutubeStreams, state); state.parseVideoSources = _.bind(parseVideoSources, state); state.getVideoMetadata = _.bind(getVideoMetadata, state); + + state.checkStartEndTimes = _.bind(checkStartEndTimes, state); } // function _renderElements(state) @@ -277,6 +279,10 @@ function (VideoPlayer) { availableQualities: ['hd720', 'hd1080', 'highres'] }; + // Make sure that start end end times are valid. If not, they will be + // set to `null` and will not be used later on. + this.checkStartEndTimes(); + // Check if the YT test timeout has been set. If not, or it is in // improper format, then set to default value. tempYtTestTimeout = parseInt(data['ytTestTimeout'], 10); @@ -360,6 +366,30 @@ function (VideoPlayer) { } } + /* + * function checkStartEndTimes() + * + * Validate config.start and config.end times. + * + * We can check at this time if the times are proper integers, and if they + * make general sense. I.e. if start time is => 0 and <= end time. + * + * An invalid start time will be reset to 0. An invalid end time will be + * set to `null`. It the task for the appropriate player API to figure out + * if start time and/or end time are greater than the length of the video. + */ + function checkStartEndTimes() { + this.config.start = parseInt(this.config.start, 10); + if ((!isFinite(this.config.start)) || (this.config.start < 0)) { + this.config.start = 0; + } + + this.config.end = parseInt(this.config.end, 10); + if ((!isFinite(this.config.end)) || (this.config.end < this.config.start)) { + this.config.end = null; + } + } + // function parseYoutubeStreams(state, youtubeStreams) // // Take a string in the form: diff --git a/common/lib/xmodule/xmodule/js/src/video/02_html5_video.js b/common/lib/xmodule/xmodule/js/src/video/02_html5_video.js index 6cd38b30bd..a82786dab2 100644 --- a/common/lib/xmodule/xmodule/js/src/video/02_html5_video.js +++ b/common/lib/xmodule/xmodule/js/src/video/02_html5_video.js @@ -191,19 +191,8 @@ function () { } // Determine the starting and ending time for the video. - this.start = 0; - this.end = null; - if (config.playerVars) { - this.start = parseFloat(config.playerVars.start); - if ((!isFinite(this.start)) || (this.start < 0)) { - this.start = 0; - } - - this.end = parseFloat(config.playerVars.end); - if ((!isFinite(this.end)) || (this.end < this.start)) { - this.end = null; - } - } + this.start = config.playerVars.start; + this.end = config.playerVars.end; // Create HTML markup for the