mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 11:01:45 +00:00
Use same audio context/source everywhere
This commit is contained in:
26
preload.js
26
preload.js
@ -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
|
||||
|
||||
Reference in New Issue
Block a user