diff options
| author | stonedDiscord <Tukz@gmx.de> | 2022-09-07 19:53:44 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-07 19:53:44 +0200 |
| commit | 5362069a05b4bfbef03f37605af979aa3cf0e066 (patch) | |
| tree | 4228d606b206aa9f7f9438a5e69e3e721bc02643 /webAO/dom/opusCheck.ts | |
| parent | 84184b35c8564a1c51cc67d9781d2463fd159527 (diff) | |
| parent | ccec95a9d3b68e25e24a9168400fc47099a85c81 (diff) | |
Merge pull request #168 from caleb-mabry/more-window-functions
More window functions
Diffstat (limited to 'webAO/dom/opusCheck.ts')
| -rw-r--r-- | webAO/dom/opusCheck.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/webAO/dom/opusCheck.ts b/webAO/dom/opusCheck.ts new file mode 100644 index 0000000..939fdc6 --- /dev/null +++ b/webAO/dom/opusCheck.ts @@ -0,0 +1,22 @@ +/** + * Triggered when there was an error loading a sound + * @param {HTMLAudioElement} image the element containing the missing sound + */ +export function opusCheck( + channel: HTMLAudioElement +): OnErrorEventHandlerNonNull { + const audio = channel.src; + if (audio === "") { + return; + } + console.info(`failed to load sound ${channel.src}`); + let oldsrc = ""; + let newsrc = ""; + 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;
\ No newline at end of file |
