Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Remove 0.25x playback on media files #182

Merged
merged 6 commits into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/lib/viewers/media/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import { addActivationListener, removeActivationListener, decodeKeydown, insertT
import { ICON_ARROW_LEFT, ICON_ARROW_RIGHT, ICON_CHECK_MARK } from '../../icons/icons';
import { CLASS_ELEM_KEYBOARD_FOCUS } from '../../constants';

const TYPE_SPEED = 'speed';
const TYPE_QUALITY = 'quality';
const CLASS_SETTINGS = 'bp-media-settings';
const CLASS_SETTINGS_SELECTED = 'bp-media-settings-selected';
const CLASS_SETTINGS_OPEN = 'bp-media-settings-is-open';
const CLASS_SETTINGS_SUBTITLES_UNAVAILABLE = 'bp-media-settings-subtitles-unavailable';
const CLASS_SETTINGS_SUBTITLES_ON = 'bp-media-settings-subtitles-on';
const SELECTOR_SETTINGS_SUB_ITEM = '.bp-media-settings-sub-item';
const SELECTOR_SETTINGS_VALUE = '.bp-media-settings-value';
const MEDIA_SPEEDS = ['0.25', '0.5', '1.0', '1.25', '1.5', '2.0'];
const MEDIA_SPEEDS = ['0.5', '1.0', '1.25', '1.5', '2.0'];

const SETTINGS_TEMPLATE = `<div class="bp-media-settings">
<div class="bp-media-settings-menu-main bp-media-settings-menu" role="menu">
Expand All @@ -37,10 +39,6 @@ const SETTINGS_TEMPLATE = `<div class="bp-media-settings">
<div class="bp-media-settings-arrow">${ICON_ARROW_LEFT}</div>
<div class="bp-media-settings-label" aria-label="${__('media_speed')}">${__('media_speed')}</div>
</div>
<div class="bp-media-settings-sub-item" data-type="speed" data-value="0.25" tabindex="0" role="menuitemradio">
<div class="bp-media-settings-icon">${ICON_CHECK_MARK}</div>
<div class="bp-media-settings-value">0.25</div>
</div>
<div class="bp-media-settings-sub-item" data-type="speed" data-value="0.5" tabindex="0" role="menuitemradio">
<div class="bp-media-settings-icon">${ICON_CHECK_MARK}</div>
<div class="bp-media-settings-value">0.5</div>
Expand Down Expand Up @@ -136,7 +134,7 @@ const SUBTITLES_SUBITEM_TEMPLATE = `<div class="bp-media-settings-sub-item" data
/**
* List of subtitles in the menu. The subtitles menu will be populated in this order
*
* @property {array}
* @property {Array}
*/
subtitles = [];

Expand Down Expand Up @@ -186,8 +184,8 @@ const SUBTITLES_SUBITEM_TEMPLATE = `<div class="bp-media-settings-sub-item" data
const quality = cache.get('media-quality') || 'auto';
const speed = cache.get('media-speed') || '1.0';

this.chooseOption('quality', quality);
this.chooseOption('speed', speed);
this.chooseOption(TYPE_QUALITY, quality);
this.chooseOption(TYPE_SPEED, speed);
}

/**
Expand Down Expand Up @@ -215,7 +213,7 @@ const SUBTITLES_SUBITEM_TEMPLATE = `<div class="bp-media-settings-sub-item" data
* Getter for testing purposes
*
* @private
* @return {array}
* @return {Array}
*/
getMediaSpeeds() {
return MEDIA_SPEEDS;
Expand All @@ -230,7 +228,7 @@ const SUBTITLES_SUBITEM_TEMPLATE = `<div class="bp-media-settings-sub-item" data
const current = parseFloat(cache.get('media-speed') || '1.0');
const higherSpeeds = MEDIA_SPEEDS.filter((speed) => parseFloat(speed) > current);
if (higherSpeeds.length > 0) {
this.chooseOption('speed', higherSpeeds[0]);
this.chooseOption(TYPE_SPEED, higherSpeeds[0]);
}
}

Expand All @@ -243,7 +241,7 @@ const SUBTITLES_SUBITEM_TEMPLATE = `<div class="bp-media-settings-sub-item" data
const current = parseFloat(cache.get('media-speed') || '1.0');
const lowerSpeeds = MEDIA_SPEEDS.filter((speed) => parseFloat(speed) < current);
if (lowerSpeeds.length > 0) {
this.chooseOption('speed', lowerSpeeds[lowerSpeeds.length - 1]);
this.chooseOption(TYPE_SPEED, lowerSpeeds[lowerSpeeds.length - 1]);
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/lib/viewers/media/__tests__/Settings-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ describe('lib/viewers/media/Settings', () => {
});

it('should not decrease speed after min', () => {
settings.chooseOption('speed', '0.5');
const speedOptions = settings.getMediaSpeeds();
expect(speedOptions.length).to.be.above(0);

settings.chooseOption('speed', speedOptions[0]);
settings.decreaseSpeed();
const speed = cache.get('media-speed');
expect(speed).to.equal('0.25');
expect(speed).to.equal(speedOptions[0]);
});
});

Expand Down