fix video player speed adjustments

This commit is contained in:
DawoudSheraz
2019-02-27 11:15:23 +05:00
parent 75161e1140
commit a5fe66863e
7 changed files with 38 additions and 28 deletions

View File

@@ -85,7 +85,7 @@
});
it('set current video speed via cookie', function() {
expect(state.speed).toEqual('1.50');
expect(state.speed).toEqual(1.5);
});
});

View File

@@ -186,7 +186,7 @@ function(Initialize) {
$.each(map, function(key, expected) {
Initialize.prototype.setSpeed.call(state, key);
expect(state.speed).toBe(expected);
expect(state.speed).toBe(parseFloat(expected));
});
});
});
@@ -205,7 +205,7 @@ function(Initialize) {
});
it('set new speed', function() {
expect(state.speed).toEqual('0.75');
expect(state.speed).toEqual(0.75);
});
});
@@ -215,7 +215,7 @@ function(Initialize) {
});
it('set speed to 1.0x', function() {
expect(state.speed).toEqual('1.0');
expect(state.speed).toEqual(1);
});
});
@@ -228,7 +228,7 @@ function(Initialize) {
$.each(map, function(key, expected) {
Initialize.prototype.setSpeed.call(state, key);
expect(state.speed).toBe(expected);
expect(state.speed).toBe(parseFloat(expected));
});
});
});

View File

@@ -56,7 +56,7 @@ function(VideoPlayer, HLS, _) {
it('create video caption', function() {
expect(state.videoCaption).toBeDefined();
expect(state.speed).toEqual('1.50');
expect(state.speed).toEqual(1.5);
expect(state.config.transcriptTranslationUrl)
.toEqual('/transcript/translation/__lang__');
});
@@ -64,7 +64,7 @@ function(VideoPlayer, HLS, _) {
it('create video speed control', function() {
expect(state.videoSpeedControl).toBeDefined();
expect(state.videoSpeedControl.el).toHaveClass('speeds');
expect(state.speed).toEqual('1.50');
expect(state.speed).toEqual(1.5);
});
it('create video progress slider', function() {

View File

@@ -715,6 +715,7 @@ function(VideoPlayer, i18n, moment, _) {
newSpeed = map[newSpeed];
this.speed = _.contains(this.speeds, newSpeed) ? newSpeed : '1.0';
}
this.speed = parseFloat(this.speed);
}
function setAutoAdvance(enabled) {

View File

@@ -231,21 +231,22 @@
* not differs from current speed.
*/
setSpeed: function(speed, silent, forceUpdate) {
if (speed !== this.currentSpeed || forceUpdate) {
var newSpeed = this.state.speedToString(speed);
if (newSpeed !== this.currentSpeed || forceUpdate) {
this.speedsContainer
.find('li')
.siblings("li[data-speed='" + speed + "']");
.siblings("li[data-speed='" + newSpeed + "']");
this.speedButton.find('.value').text(speed + 'x');
this.currentSpeed = speed;
this.speedButton.find('.value').text(newSpeed + 'x');
this.currentSpeed = newSpeed;
if (!silent) {
this.el.trigger('speedchange', [speed, this.state.speed]);
this.el.trigger('speedchange', [newSpeed, this.state.speed]);
}
}
this.resetActiveSpeed();
this.setActiveSpeed(speed);
this.setActiveSpeed(newSpeed);
},
resetActiveSpeed: function() {
@@ -259,13 +260,13 @@
},
setActiveSpeed: function(speed) {
var speedOption = this.speedsContainer.find('li[data-speed="' + speed + '"]');
var speedOption = this.speedsContainer.find('li[data-speed="' + this.state.speedToString(speed) + '"]');
speedOption.addClass('is-active')
.find('.speed-option')
.attr('aria-pressed', 'true');
this.speedButton.attr('title', gettext('Video speed: ') + speed + 'x');
this.speedButton.attr('title', gettext('Video speed: ') + this.state.speedToString(speed) + 'x');
},
/**

View File

@@ -217,7 +217,8 @@ function(Component) {
},
appendContent: function(content) {
this.getElement().append(content);
var $content = $(content);
this.getElement().append($content);
return this;
},
@@ -247,8 +248,8 @@ function(Component) {
},
open: function() {
var menu = (this.isRendered) ? this.getElement() : this.populateElement();
this.container.append(menu);
var $menu = (this.isRendered) ? this.getElement() : this.populateElement();
this.container.append($menu);
AbstractItem.prototype.open.call(this);
this.overlay.show(this.container);
return this;
@@ -355,7 +356,8 @@ function(Component) {
},
show: function(container) {
$(container).append(this.getElement());
var $elem = $(this.getElement());
$(container).append($elem);
this.delegateEvents();
return this;
},
@@ -390,7 +392,9 @@ function(Component) {
},
createElement: function() {
var $element = $('<li />', {
var $spanElem,
$listElem,
$element = $('<li />', {
class: ['submenu-item', 'menu-item', this.options.prefix + 'submenu-item'].join(' '),
'aria-expanded': 'false',
'aria-haspopup': 'true',
@@ -399,21 +403,25 @@ function(Component) {
tabindex: -1
});
this.label = $('<span />', {
$spanElem = $('<span />', {
id: 'submenu-item-label-' + this.id,
text: this.options.label
}).appendTo($element);
});
this.label = $spanElem.appendTo($element);
this.list = $('<ol />', {
$listElem = $('<ol />', {
class: ['submenu', this.options.prefix + 'submenu'].join(' '),
role: 'menu'
}).appendTo($element);
});
this.list = $listElem.appendTo($element);
return $element;
},
appendContent: function(content) {
this.list.append(content);
var $content = $(content);
this.list.append($content);
return this;
},
@@ -628,7 +636,7 @@ function(Component) {
}, {
label: i18n.Speed,
items: _.map(state.speeds, function(speed) {
var isSelected = speed === state.speed;
var isSelected = parseFloat(speed) === state.speed;
return {label: speed + 'x', callback: speedCallback, speed: speed, isSelected: isSelected};
}),
initialize: function(menuitem) {

View File

@@ -101,8 +101,8 @@
onSpeedChange: function(event, newSpeed, oldSpeed) {
this.log('speed_change_video', {
current_time: this.getCurrentTime(),
old_speed: oldSpeed,
new_speed: newSpeed
old_speed: this.state.speedToString(oldSpeed),
new_speed: this.state.speedToString(newSpeed)
});
},