Skip to content

Commit

Permalink
Make speed UI update when changed from another source. (such as the i…
Browse files Browse the repository at this point in the history
…Pad video menu)
  • Loading branch information
nholtman committed Sep 20, 2024
1 parent d3bf82b commit e4013e6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@A-VISION-BV/mediaelement-plugins",
"version": "4.1.0",
"version": "4.1.1",
"repository": {
"type": "git",
"url": "https://github.com/A-VISION-BV/mediaelement-plugins.git"
Expand Down
40 changes: 32 additions & 8 deletions src/speed/speed.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ Object.assign(MediaElementPlayer.prototype, {
speedButton.setAttribute('aria-expanded', 'true');

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

menuIsHidden = false;
}
Expand Down Expand Up @@ -280,14 +283,22 @@ Object.assign(MediaElementPlayer.prototype, {
media.addEventListener('loadedmetadata', () => {
if (currentPlaybackSpeed) {
media.playbackRate = Number(currentPlaybackSpeed);
speedButton.innerHTML = getSpeedNameFromValue(currentPlaybackSpeed)
}
});


function handleChangeSpeed() {
media.addEventListener('ratechange', () => {
const numericPlaybackRate = Number(media.playbackRate);
if (numericPlaybackRate != currentPlaybackSpeed) {
currentPlaybackSpeed = numericPlaybackRate;
}
speedButton.innerHTML = getSpeedNameFromValue(currentPlaybackSpeed);



const total = radios.length;
for(let i = 0; i < total; i++) {
const radio = radios[i]
const radio = radios[i];

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

// handle the new speed.
if (radio.checked) {
const radioSpeed = Number(radio.value)
if(radioSpeed == numericPlaybackRate) {

radio.checked = true;

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

Expand All @@ -306,12 +319,23 @@ Object.assign(MediaElementPlayer.prototype, {
for (let i = 0, total = siblings.length; i < total; i++) {
mejs.Utils.addClass(siblings[i], `${t.options.classPrefix}speed-selected`);
}
}
}

});


function handleChangeSpeed() {
const total = radios.length;
for(let i = 0; i < total; i++) {
const radio = radios[i]

// handle the new speed.
if (radio.checked) {

// set the speed onto the media
const newSpeed = Number(radio.value)
media.playbackRate = newSpeed
currentPlaybackSpeed = newSpeed
speedButton.innerHTML = getSpeedNameFromValue(newSpeed)
}
}
}
Expand Down

0 comments on commit e4013e6

Please sign in to comment.