Skip to content

Commit

Permalink
add/remove muted attribute
Browse files Browse the repository at this point in the history
Unless the attribute is actually on the element, the browser doesn't recognise it as muted and won't autoplay.
Also added missing volumechange handler to audio
  • Loading branch information
edsilv committed Jan 16, 2025
1 parent b31aa64 commit 22ff0ce
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,15 @@ export class MediaElementCenterPanel extends CenterPanel<
}
});

this.extensionHost.subscribe(IIIFEvents.SET_MUTED, (muted) => {
this.extensionHost.subscribe(IIIFEvents.SET_MUTED, (muted: boolean) => {
if (that.player) {
that.player.setMuted(muted);

if (muted) {
that.$media.attr("muted", "");
} else {
that.$media.removeAttr("muted");
}
}
});

Expand Down Expand Up @@ -351,6 +357,22 @@ export class MediaElementCenterPanel extends CenterPanel<
Math.floor(mediaElement.currentTime)
);
});

mediaElement.addEventListener("volumechange", (volume) => {
const muted: boolean = volume.detail.target.getMuted();

if (that.muted === false && muted === true) {
that.muted = true;
that.extensionHost.fire(MediaElementExtensionEvents.MEDIA_MUTED);
}

if (that.muted === true && muted === false) {
that.muted = false;
that.extensionHost.fire(
MediaElementExtensionEvents.MEDIA_UNMUTED
);
}
});
},
});
}
Expand Down

0 comments on commit 22ff0ce

Please sign in to comment.