aboutsummaryrefslogtreecommitdiff
path: root/webAO/dom/opusCheck.ts
blob: 5f0248daa7a34aa0d1c8ea7bbcd7031fd94cdcd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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.warn(`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;