Skip to content

Commit e4013e6

Browse files
committed
Make speed UI update when changed from another source. (such as the iPad video menu)
1 parent d3bf82b commit e4013e6

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@A-VISION-BV/mediaelement-plugins",
3-
"version": "4.1.0",
3+
"version": "4.1.1",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/A-VISION-BV/mediaelement-plugins.git"

src/speed/speed.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ Object.assign(MediaElementPlayer.prototype, {
203203
speedButton.setAttribute('aria-expanded', 'true');
204204

205205
// focus on selected radio input
206-
speedList.querySelector('.' + t.options.classPrefix + 'speed-selected-input').focus();
206+
const selectedSpeedInput = speedList.querySelector('.' + t.options.classPrefix + 'speed-selected-input')
207+
if(selectedSpeedInput != undefined) {
208+
selectedSpeedInput.focus();
209+
}
207210

208211
menuIsHidden = false;
209212
}
@@ -280,14 +283,22 @@ Object.assign(MediaElementPlayer.prototype, {
280283
media.addEventListener('loadedmetadata', () => {
281284
if (currentPlaybackSpeed) {
282285
media.playbackRate = Number(currentPlaybackSpeed);
286+
speedButton.innerHTML = getSpeedNameFromValue(currentPlaybackSpeed)
283287
}
284288
});
285289

286-
287-
function handleChangeSpeed() {
290+
media.addEventListener('ratechange', () => {
291+
const numericPlaybackRate = Number(media.playbackRate);
292+
if (numericPlaybackRate != currentPlaybackSpeed) {
293+
currentPlaybackSpeed = numericPlaybackRate;
294+
}
295+
speedButton.innerHTML = getSpeedNameFromValue(currentPlaybackSpeed);
296+
297+
298+
288299
const total = radios.length;
289300
for(let i = 0; i < total; i++) {
290-
const radio = radios[i]
301+
const radio = radios[i];
291302

292303
// remove the speed-selected class from the previous selected speed label
293304
mejs.Utils.removeClass(radio, `${t.options.classPrefix}speed-selected-input`);
@@ -296,8 +307,10 @@ Object.assign(MediaElementPlayer.prototype, {
296307
mejs.Utils.removeClass(siblings[i], `${t.options.classPrefix}speed-selected`);
297308
}
298309

299-
// handle the new speed.
300-
if (radio.checked) {
310+
const radioSpeed = Number(radio.value)
311+
if(radioSpeed == numericPlaybackRate) {
312+
313+
radio.checked = true;
301314

302315
mejs.Utils.addClass(radio, `${t.options.classPrefix}speed-selected-input`);
303316

@@ -306,12 +319,23 @@ Object.assign(MediaElementPlayer.prototype, {
306319
for (let i = 0, total = siblings.length; i < total; i++) {
307320
mejs.Utils.addClass(siblings[i], `${t.options.classPrefix}speed-selected`);
308321
}
322+
}
323+
}
324+
325+
});
326+
327+
328+
function handleChangeSpeed() {
329+
const total = radios.length;
330+
for(let i = 0; i < total; i++) {
331+
const radio = radios[i]
332+
333+
// handle the new speed.
334+
if (radio.checked) {
309335

310336
// set the speed onto the media
311337
const newSpeed = Number(radio.value)
312338
media.playbackRate = newSpeed
313-
currentPlaybackSpeed = newSpeed
314-
speedButton.innerHTML = getSpeedNameFromValue(newSpeed)
315339
}
316340
}
317341
}

0 commit comments

Comments
 (0)