From 0e24ff14f381522ae52eb57d49694e028f538ac1 Mon Sep 17 00:00:00 2001 From: Valera Rozuvan Date: Mon, 1 Apr 2013 09:33:41 +0300 Subject: [PATCH] Added fade in/fade out for controls in HTML5 videos. Making video in the center and not stretched when captions are shown. Added auto hide/show for captions. Removed old styling and debug info. Added missing initalizations for captions auto show/hide. Fixing bugs. Adding black backgorund to video for when it has not yet loaded. Making sure that the captions are not shown when in YouTube mode. Added back missing styles for captions when in YouTube mode. Code review 1 comments Minor refactoring. Documenting. Part 1. --- .../xmodule/css/videoalpha/display.scss | 66 ++++++-- .../xmodule/js/src/videoalpha/display/bind.js | 19 --- .../js/src/videoalpha/display/html5_video.js | 39 +++-- .../js/src/videoalpha/display/initialize.js | 154 ++++++++++++------ .../src/videoalpha/display/video_caption.js | 104 +++++++++--- .../src/videoalpha/display/video_control.js | 124 ++++++-------- .../js/src/videoalpha/display/video_player.js | 63 ++++--- .../display/video_progress_slider.js | 18 +- .../display/video_quality_control.js | 10 +- .../videoalpha/display/video_speed_control.js | 12 +- .../display/video_volume_control.js | 12 +- .../lib/xmodule/xmodule/videoalpha_module.py | 1 - lms/templates/videoalpha.html | 3 +- 13 files changed, 370 insertions(+), 255 deletions(-) delete mode 100644 common/lib/xmodule/xmodule/js/src/videoalpha/display/bind.js diff --git a/common/lib/xmodule/xmodule/css/videoalpha/display.scss b/common/lib/xmodule/xmodule/css/videoalpha/display.scss index ee5b83d274..c677584484 100644 --- a/common/lib/xmodule/xmodule/css/videoalpha/display.scss +++ b/common/lib/xmodule/xmodule/css/videoalpha/display.scss @@ -10,11 +10,29 @@ div.videoalpha { padding: 12px; border-radius: 5px; + div.tc-wrapper { + position: relative; + } + article.video-wrapper { float: left; margin-right: flex-gutter(9); width: flex-grid(6, 9); + background-color: black; + + position: relative; + + div.video-player-pre { + height: 50px; + background-color: black; + } + + div.video-player-post { + height: 50px; + background-color: black; + } + section.video-player { height: 0; overflow: hidden; @@ -31,15 +49,6 @@ div.videoalpha { } } - section.video-roof { - background-color: green; - z-index: 10000; - width: 540px; - height: 100px; - position: absolute; - top: 387px; - } - section.video-controls { @include clearfix(); background: #333; @@ -396,7 +405,6 @@ div.videoalpha { a.hide-subtitles { background: url('../images/cc.png') center no-repeat; - color: #797979; display: block; float: left; font-weight: 800; @@ -419,6 +427,10 @@ div.videoalpha { &.off { opacity: 0.7; } + + background-color: #444; + color: #fff; + text-decoration: none; } } } @@ -480,11 +492,39 @@ div.videoalpha { article.video-wrapper { width: flex-grid(9,9); + + background-color: inherit; + } + + article.video-wrapper section.video-controls.html5 { + bottom: 0px; + left: 0px; + right: 0px; + position: absolute; + } + + article.video-wrapper section.video-controls div.secondary-controls a.hide-subtitles { + background-color: inherit; + color: #797979; + text-decoration: inherit; + } + + article.video-wrapper div.video-player-pre, article.video-wrapper div.video-player-post { + height: 0px; } ol.subtitles { - width: 0; - height: 0; + width: 0; + height: 0; + } + + ol.subtitles.html5 { + background-color: rgba(243, 243, 243, 0.5); + height: 380px; + position: absolute; + right: 0; + width: 275px; + margin-top: 20px; } } @@ -545,7 +585,7 @@ div.videoalpha { background: rgba(#000, .8); bottom: 0; height: 100%; - max-height: 100%; + max-height: 460px; max-width: flex-grid(3); padding: lh(); position: fixed; diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/display/bind.js b/common/lib/xmodule/xmodule/js/src/videoalpha/display/bind.js deleted file mode 100644 index a5bdf66af0..0000000000 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/display/bind.js +++ /dev/null @@ -1,19 +0,0 @@ -(function (requirejs, require, define) { - -// Bind module. -define( -'videoalpha/display/bind.js', -[], -function () { - - // bind() function. - return function (fn, me) { - return function () { - return fn.apply(me, arguments); - }; - }; - -}); - -}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); -// var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, diff --git a/common/lib/xmodule/xmodule/js/src/videoalpha/display/html5_video.js b/common/lib/xmodule/xmodule/js/src/videoalpha/display/html5_video.js index 0b9ff0148a..91f36556b7 100644 --- a/common/lib/xmodule/xmodule/js/src/videoalpha/display/html5_video.js +++ b/common/lib/xmodule/xmodule/js/src/videoalpha/display/html5_video.js @@ -1,6 +1,18 @@ +/** + * @file HTML5 video player module. Provides methods to control the in-browser HTML5 video player. + * + * The goal was to write this module so that it closely resembles the YouTube API. The main reason + * for this is because initially the edX video player supported only YouTube videos. When HTML5 + * support was added, for greater compatibility, and to reduce the amount of code that needed to + * be modified, it was decided to write a similar API as the one provided by YouTube. + * + * @external RequireJS + * + * @module HTML5Video + */ + (function (requirejs, require, define) { -// HTML5Video module. define( 'videoalpha/display/html5_video.js', [], @@ -11,7 +23,7 @@ function () { HTML5Video.Player = (function () { Player.prototype.callStateChangeCallback = function () { - if ($.isFunction(this.config.events.onStateChange) === true) { + if ($.isFunction(this.config.events.onStateChange)) { this.config.events.onStateChange({ 'data': this.playerState }); @@ -62,7 +74,7 @@ function () { newSpeed = parseFloat(value); - if (isFinite(newSpeed) === true) { + if (isFinite(newSpeed)) { this.video.playbackRate = value; } }; @@ -76,10 +88,10 @@ function () { /* * Constructor function for HTML5 Video player. * - * @el - A DOM element where the HTML5 player will be inserted (as returned by jQuery(selector) function), + * @param {String|Object} el A DOM element where the HTML5 player will be inserted (as returned by jQuery(selector) function), * or a selector string which will be used to select an element. This is a required parameter. * - * @config - An object whose properties will be used as configuration options for the HTML5 video + * @param config - An object whose properties will be used as configuration options for the HTML5 video * player. This is an optional parameter. In the case if this parameter is missing, or some of the config * object's properties are missing, defaults will be used. The available options (and their defaults) are as * follows: @@ -130,14 +142,14 @@ function () { } // A simple test to see that the 'config' is a normal object. - if ($.isPlainObject(config) === true) { + if ($.isPlainObject(config)) { this.config = config; } else { return; } // We should have at least one video source. Otherwise there is no point to continue. - if (config.hasOwnProperty('videoSources') === false) { + if (!config.videoSources) { return; } @@ -154,9 +166,8 @@ function () { // Create HTML markup for individual sources of the HTML5