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
@@ -78,7 +78,7 @@ videos:
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
{% endcapture %} {% endcapture %}
{% include blocks/media.liquid type="video" caption=caption poster=video.poster muted=true preload="none" player=true content=video_sources %} {% include blocks/media.liquid type="video" caption=caption poster=video.poster preload="metadata" player=true content=video_sources %}
</script> </script>
{% endcapture %} {% endcapture %}
{% include blocks/details.liquid title=video.name content=capture_video level=1 open=true %} {% include blocks/details.liquid title=video.name content=capture_video level=1 open=true %}
+15 -1
View File
@@ -223,6 +223,17 @@ async function xmr_initialize_player(el) {
}); });
el.hideOverlay(); 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 // Variants
let variant = el.querySelector(".variant"); let variant = el.querySelector(".variant");
variant.update = function() { variant.update = function() {
@@ -257,7 +268,7 @@ async function xmr_initialize_player(el) {
variant.addEventListener("input", () => { variant.update(); }); variant.addEventListener("input", () => { variant.update(); });
variant.addEventListener("value", () => { variant.update(); }); variant.addEventListener("value", () => { variant.update(); });
// Add options from available sources. // Variants - Add options from available sources.
let sources = el.querySelectorAll("source"); let sources = el.querySelectorAll("source");
for (let k of sources) { for (let k of sources) {
let option = document.createElement("option"); let option = document.createElement("option");
@@ -266,6 +277,9 @@ async function xmr_initialize_player(el) {
variant.appendChild(option); variant.appendChild(option);
} }
variant.value = media.currentSrc; variant.value = media.currentSrc;
// Signal the browser to try and load some information.
media.load();
} }
async function xmr_initialize_players() { async function xmr_initialize_players() {