From 60a9867a0551753101f5b4d692fa5a9ea77aba2a Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Sat, 18 Sep 2021 16:00:43 +0200 Subject: try to load opus versions of mp3 tracks if they are missing --- webAO/client.html | 6 +++--- webAO/client.js | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/webAO/client.html b/webAO/client.html index dd036a6..a31938c 100644 --- a/webAO/client.html +++ b/webAO/client.html @@ -373,13 +373,13 @@ onchange="changeMusicVolume()">

SFX

- +

Shouts

- +

Testimony/Guilty

- +

Blip

channel.volume = 0.5); + this.blipChannels.forEach(channel => channel.onerror = opusCheck(channel)); this.currentBlipChannel = 0; this.sfxaudio = document.getElementById("client_sfxaudio"); @@ -1666,6 +1667,7 @@ class Viewport { new Audio(`${AO_HOST}sounds/music/trial (aa).opus`), new Audio(`${AO_HOST}sounds/music/trial (aa).opus`)); this.music.forEach(channel => channel.volume = 0.5); + this.music.forEach(channel => channel.onerror = opusCheck(channel)); this.updater = null; this.testimonyUpdater = null; @@ -2691,6 +2693,23 @@ export function imgError(image) { } window.imgError = imgError; +/** + * Triggered when there was an error loading a sound + * @param {HTMLImageElement} image the element containing the missing sound + */ + export function opusCheck(channel) { + console.info(channel) + console.info("failed to load sound "+channel.src) + let oldsrc = "" + oldsrc = channel.src + if(!oldsrc.endsWith(".opus")) { + newsrc = oldsrc.replace(".mp3",".opus") + newsrc = newsrc.replace(".wav",".opus") + channel.src = newsrc; //unload so the old sprite doesn't persist + } +} +window.opusCheck = opusCheck; + /** * Make a GET request for a specific URI. * @param {string} url the URI to be requested -- cgit