Use same audio context/source everywhere

This commit is contained in:
TC
2023-01-08 19:17:00 +01:00
parent fcb92fda84
commit 52b67af59c
5 changed files with 135 additions and 62 deletions

View File

@ -90,6 +90,32 @@ function listenForApiLoad() {
}
function onApiLoaded() {
const video = document.querySelector("video");
const audioContext = new AudioContext();
const audioSource = audioContext.createMediaElementSource(video);
video.addEventListener(
"loadstart",
() => {
// Emit "audioCanPlay" for each video
video.addEventListener(
"canplaythrough",
() => {
document.dispatchEvent(
new CustomEvent("audioCanPlay", {
detail: {
audioContext: audioContext,
audioSource: audioSource,
},
})
);
},
{ once: true }
);
},
{ passive: true }
);
document.dispatchEvent(new CustomEvent('apiLoaded', { detail: api }));
// Remove upgrade button