mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
Use a promise to wait for transitions in crossfade plugin
This commit is contained in:
@ -6,7 +6,7 @@ require("./fader");
|
|||||||
|
|
||||||
let transitionAudio; // Howler audio used to fade out the current music
|
let transitionAudio; // Howler audio used to fade out the current music
|
||||||
let firstVideo = true;
|
let firstVideo = true;
|
||||||
let transitioning = false;
|
let waitForTransition;
|
||||||
|
|
||||||
// Crossfade options that can be overridden in plugin options
|
// Crossfade options that can be overridden in plugin options
|
||||||
let crossfadeOptions = {
|
let crossfadeOptions = {
|
||||||
@ -109,10 +109,9 @@ const syncVideoWithTransitionAudio = async () => {
|
|||||||
|
|
||||||
const onApiLoaded = () => {
|
const onApiLoaded = () => {
|
||||||
watchVideoIDChanges(async (videoID) => {
|
watchVideoIDChanges(async (videoID) => {
|
||||||
if (!transitioning) {
|
await waitForTransition;
|
||||||
const url = await getStreamURL(videoID);
|
const url = await getStreamURL(videoID);
|
||||||
await createAudioForCrossfade(url);
|
await createAudioForCrossfade(url);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -121,7 +120,11 @@ const crossfade = (cb) => {
|
|||||||
cb();
|
cb();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
transitioning = true;
|
|
||||||
|
let resolveTransition;
|
||||||
|
waitForTransition = new Promise(function (resolve, reject) {
|
||||||
|
resolveTransition = resolve;
|
||||||
|
});
|
||||||
|
|
||||||
const video = document.querySelector("video");
|
const video = document.querySelector("video");
|
||||||
|
|
||||||
@ -134,7 +137,7 @@ const crossfade = (cb) => {
|
|||||||
// Fade out the music
|
// Fade out the music
|
||||||
video.volume = 0;
|
video.volume = 0;
|
||||||
fader.fadeOut(() => {
|
fader.fadeOut(() => {
|
||||||
transitioning = false;
|
resolveTransition();
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user