media: Hide audio controls if there is no audio

This commit is contained in:
Michael Fabian 'Xaymar' Dirks
2022-11-27 02:24:53 +01:00
parent 4ccdd5391e
commit d38e7a5974
2 changed files with 16 additions and 2 deletions
+15 -1
View File
@@ -223,6 +223,17 @@ async function xmr_initialize_player(el) {
});
el.hideOverlay();
// Show/Hide Audio controls without audio.
function checkAudioPresence() {
let hasAudio = Boolean(media.mozHasAudio)
|| Boolean(media.webkitAudioDecodedByteCount)
|| Boolean(media.audioTracks && media.audioTracks.length);
audio_mute.style.display = hasAudio ? "" : "none";
audio_volume.style.display = hasAudio ? "" : "none";
}
media.addEventListener("loadedmetadata", () => { checkAudioPresence() });
checkAudioPresence();
// Variants
let variant = el.querySelector(".variant");
variant.update = function() {
@@ -257,7 +268,7 @@ async function xmr_initialize_player(el) {
variant.addEventListener("input", () => { variant.update(); });
variant.addEventListener("value", () => { variant.update(); });
// Add options from available sources.
// Variants - Add options from available sources.
let sources = el.querySelectorAll("source");
for (let k of sources) {
let option = document.createElement("option");
@@ -266,6 +277,9 @@ async function xmr_initialize_player(el) {
variant.appendChild(option);
}
variant.value = media.currentSrc;
// Signal the browser to try and load some information.
media.load();
}
async function xmr_initialize_players() {