mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-13 19:31:46 +00:00
Merge branch 'master' into use-ToastXML
This commit is contained in:
26
preload.js
26
preload.js
@ -97,6 +97,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 }));
|
||||
ipcRenderer.send('apiLoaded');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user