Skip to content

Commit

Permalink
Update: Remove 0.25x playback on media files (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Minh-Ng authored and tonyjin committed Jun 23, 2017
1 parent a344153 commit 896c755
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
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

0 comments on commit 896c755

Please sign in to comment.