Commit c08e21c3 by Anton Stupak

Merge pull request #3678 from edx/anton/refactor-volume-control

Video: refactor volume control.
parents d01af063 8c26fc68
...@@ -458,14 +458,14 @@ div.video { ...@@ -458,14 +458,14 @@ div.video {
float: left; float: left;
position: relative; position: relative;
&.open { &.is-opened {
.volume-slider-container { .volume-slider-container {
display: block; display: block;
opacity: 1; opacity: 1;
} }
} }
&.muted { &.is-muted {
& > a { & > a {
background-image: url('../images/mute.png'); background-image: url('../images/mute.png');
} }
......
...@@ -141,8 +141,7 @@ function (VideoPlayer) { ...@@ -141,8 +141,7 @@ function (VideoPlayer) {
state.videoEl = $('video, iframe'); state.videoEl = $('video, iframe');
expect(state.videoVolumeControl).toBeUndefined(); expect(state.el.find('.volume')).not.toExist();
expect(state.el.find('div.volume')).not.toExist();
}); });
}); });
}); });
...@@ -450,7 +449,6 @@ function (VideoPlayer) { ...@@ -450,7 +449,6 @@ function (VideoPlayer) {
}, 'currentTime got updated', 10000); }, 'currentTime got updated', 10000);
}); });
}); });
});
describe('when the video is not playing', function () { describe('when the video is not playing', function () {
beforeEach(function () { beforeEach(function () {
...@@ -472,20 +470,13 @@ function (VideoPlayer) { ...@@ -472,20 +470,13 @@ function (VideoPlayer) {
expect(state.videoPlayer.setPlaybackRate.calls.length) expect(state.videoPlayer.setPlaybackRate.calls.length)
.toEqual(1); .toEqual(1);
}); });
it('video has a correct volume', function () {
spyOn(state.videoPlayer.player, 'setVolume');
state.currentVolume = '0.26';
state.videoPlayer.onPlay();
expect(state.videoPlayer.player.setVolume)
.toHaveBeenCalledWith('0.26');
}); });
}); });
describe('onVolumeChange', function () { describe('onVolumeChange', function () {
beforeEach(function () { beforeEach(function () {
state = jasmine.initializePlayer(); state = jasmine.initializePlayer();
state.videoPlayer.onReady();
state.videoEl = $('video, iframe'); state.videoEl = $('video, iframe');
}); });
...@@ -502,10 +493,10 @@ function (VideoPlayer) { ...@@ -502,10 +493,10 @@ function (VideoPlayer) {
it('video has a correct volume', function () { it('video has a correct volume', function () {
spyOn(state.videoPlayer.player, 'setVolume'); spyOn(state.videoPlayer.player, 'setVolume');
state.currentVolume = '0.26'; state.videoVolumeControl.volume = 26;
state.videoPlayer.onPlay(); state.el.trigger('play');
expect(state.videoPlayer.player.setVolume) expect(state.videoPlayer.player.setVolume)
.toHaveBeenCalledWith('0.26'); .toHaveBeenCalledWith(26);
}); });
}); });
}); });
......
(function (define) {
'use strict';
define(
'video/00_i18n.js',
[],
function() {
/**
* i18n module.
* @exports video/00_i18n.js
* @return {object}
*/
return {
'Volume': gettext('Volume'),
// Translators: Volume level equals 0%.
'Muted': gettext('Muted'),
// Translators: Volume level in range ]0,20]%
'Very low': gettext('Very low'),
// Translators: Volume level in range ]20,40]%
'Low': gettext('Low'),
// Translators: Volume level in range ]40,60]%
'Average': gettext('Average'),
// Translators: Volume level in range ]60,80]%
'Loud': gettext('Loud'),
// Translators: Volume level in range ]80,99]%
'Very loud': gettext('Very loud'),
// Translators: Volume level equals 100%.
'Maximum': gettext('Maximum')
};
});
}(RequireJS.define));
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
define( define(
'video/01_initialize.js', 'video/01_initialize.js',
['video/03_video_player.js', 'video/00_video_storage.js'], ['video/03_video_player.js', 'video/00_video_storage.js', 'video/00_i18n.js'],
function (VideoPlayer, VideoStorage) { function (VideoPlayer, VideoStorage, i18n) {
/** /**
* @function * @function
* *
...@@ -39,7 +39,7 @@ function (VideoPlayer, VideoStorage) { ...@@ -39,7 +39,7 @@ function (VideoPlayer, VideoStorage) {
return false; return false;
} }
_initializeModules(state) _initializeModules(state, i18n)
.done(function () { .done(function () {
// On iPad ready state occurs just after start playing. // On iPad ready state occurs just after start playing.
// We hide controls before video starts playing. // We hide controls before video starts playing.
...@@ -341,11 +341,11 @@ function (VideoPlayer, VideoStorage) { ...@@ -341,11 +341,11 @@ function (VideoPlayer, VideoStorage) {
state.captionHideTimeout = null; state.captionHideTimeout = null;
} }
function _initializeModules(state) { function _initializeModules(state, i18n) {
var dfd = $.Deferred(), var dfd = $.Deferred(),
modulesList = $.map(state.modules, function(module) { modulesList = $.map(state.modules, function(module) {
if ($.isFunction(module)) { if ($.isFunction(module)) {
return module(state); return module(state, i18n);
} else if ($.isPlainObject(module)) { } else if ($.isPlainObject(module)) {
return module; return module;
} }
...@@ -494,7 +494,6 @@ function (VideoPlayer, VideoStorage) { ...@@ -494,7 +494,6 @@ function (VideoPlayer, VideoStorage) {
__dfd__: __dfd__, __dfd__: __dfd__,
el: el, el: el,
container: container, container: container,
currentVolume: 100,
id: id, id: id,
isFullScreen: false, isFullScreen: false,
isTouch: isTouch, isTouch: isTouch,
......
...@@ -98,7 +98,6 @@ function (HTML5Video, Resizer) { ...@@ -98,7 +98,6 @@ function (HTML5Video, Resizer) {
if (!state.isFlashMode() && state.speed != '1.0') { if (!state.isFlashMode() && state.speed != '1.0') {
state.videoPlayer.setPlaybackRate(state.speed); state.videoPlayer.setPlaybackRate(state.speed);
} }
state.videoPlayer.player.setVolume(state.currentVolume);
}); });
if (state.isYoutubeType()) { if (state.isYoutubeType()) {
...@@ -584,6 +583,10 @@ function (HTML5Video, Resizer) { ...@@ -584,6 +583,10 @@ function (HTML5Video, Resizer) {
_this.videoPlayer.onSpeedChange(speed); _this.videoPlayer.onSpeedChange(speed);
}); });
this.el.on('volumechange volumechange:silent', function (event, volume) {
_this.videoPlayer.onVolumeChange(volume);
});
this.videoPlayer.log('load_video'); this.videoPlayer.log('load_video');
availablePlaybackRates = this.videoPlayer.player availablePlaybackRates = this.videoPlayer.player
...@@ -919,7 +922,6 @@ function (HTML5Video, Resizer) { ...@@ -919,7 +922,6 @@ function (HTML5Video, Resizer) {
function onVolumeChange(volume) { function onVolumeChange(volume) {
this.videoPlayer.player.setVolume(volume); this.videoPlayer.player.setVolume(volume);
this.el.trigger('volumechange', arguments);
} }
}); });
......
...@@ -64,9 +64,9 @@ function () { ...@@ -64,9 +64,9 @@ function () {
state.videoQualityControl.el.on('click', state.videoQualityControl.el.on('click',
state.videoQualityControl.toggleQuality state.videoQualityControl.toggleQuality
); );
state.el.on('play', state.el.on('play', _.once(function () {
_.once(state.videoQualityControl.fetchAvailableQualities) state.videoQualityControl.fetchAvailableQualities();
); }));
} }
// *************************************************************** // ***************************************************************
......
...@@ -9,6 +9,7 @@ function (Iterator) { ...@@ -9,6 +9,7 @@ function (Iterator) {
* @exports video/08_video_speed_control.js * @exports video/08_video_speed_control.js
* @constructor * @constructor
* @param {object} state The object containing the state of the video player. * @param {object} state The object containing the state of the video player.
* @return {jquery Promise}
*/ */
var SpeedControl = function (state) { var SpeedControl = function (state) {
if (!(this instanceof SpeedControl)) { if (!(this instanceof SpeedControl)) {
......
...@@ -71,6 +71,7 @@ class VideoModule(VideoFields, VideoStudentViewHandlers, XModule): ...@@ -71,6 +71,7 @@ class VideoModule(VideoFields, VideoStudentViewHandlers, XModule):
resource_string(module, 'js/src/video/00_video_storage.js'), resource_string(module, 'js/src/video/00_video_storage.js'),
resource_string(module, 'js/src/video/00_resizer.js'), resource_string(module, 'js/src/video/00_resizer.js'),
resource_string(module, 'js/src/video/00_async_process.js'), resource_string(module, 'js/src/video/00_async_process.js'),
resource_string(module, 'js/src/video/00_i18n.js'),
resource_string(module, 'js/src/video/00_sjson.js'), resource_string(module, 'js/src/video/00_sjson.js'),
resource_string(module, 'js/src/video/00_iterator.js'), resource_string(module, 'js/src/video/00_iterator.js'),
resource_string(module, 'js/src/video/01_initialize.js'), resource_string(module, 'js/src/video/01_initialize.js'),
......
...@@ -79,8 +79,8 @@ ...@@ -79,8 +79,8 @@
<ol class="video-speeds menu" role="menu"></ol> <ol class="video-speeds menu" role="menu"></ol>
</div> </div>
<div class="volume"> <div class="volume">
<a href="#" title="${_('Volume')}" role="button" aria-disabled="false"></a> <a href="#" role="button" aria-disabled="false" title="${_('Volume')}" aria-label="${_('Click on this button to mute or unmute this video or press UP or DOWN buttons to increase or decrease volume level.')}"></a>
<div class="volume-slider-container"> <div role="presentation" class="volume-slider-container">
<div class="volume-slider"></div> <div class="volume-slider"></div>
</div> </div>
</div> </div>
......
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