getSongUrl
This commit is contained in:
63
index.html
63
index.html
@@ -1277,31 +1277,43 @@
|
|||||||
}, [playlist, currentSong, mode, volume, quality]);
|
}, [playlist, currentSong, mode, volume, quality]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
let isMounted = true;
|
||||||
if (currentSong) {
|
if (currentSong) {
|
||||||
const audio = audioRef.current;
|
const audio = audioRef.current;
|
||||||
if (!audio) return;
|
if (!audio) return;
|
||||||
// Update URL when quality changes or song changes
|
|
||||||
const url = api.getSongUrl(currentSong.id, currentSong.platform || currentSong.source, quality);
|
const fetchAndPlay = async () => {
|
||||||
|
// Update URL when quality changes or song changes
|
||||||
// Only update src if it's different to avoid reloading same song on re-render (unless quality changed)
|
const url = await api.getSongUrl(currentSong.id, currentSong.platform || currentSong.source, quality);
|
||||||
// Note: audioRef.current.src returns full absolute URL
|
|
||||||
const currentSrc = audio.src;
|
if (!isMounted || !url) return;
|
||||||
const wasPlaying = isPlaying;
|
|
||||||
const deferOnIOS = autoNextPendingRef.current;
|
// Check if song changed while fetching
|
||||||
autoNextPendingRef.current = false;
|
if (currentSongRef.current?.id !== currentSong.id) return;
|
||||||
|
|
||||||
// Simple check if src changed significantly (avoiding minor encoding diffs if possible, but exact match is safer)
|
// Only update src if it's different to avoid reloading same song on re-render (unless quality changed)
|
||||||
if (currentSrc !== url) {
|
// Note: audioRef.current.src returns full absolute URL
|
||||||
audio.src = url;
|
const currentSrc = audio.src;
|
||||||
if (wasPlaying) {
|
const wasPlaying = isPlaying;
|
||||||
playAudioWithFallback(audio, { deferOnIOS });
|
const deferOnIOS = autoNextPendingRef.current;
|
||||||
|
autoNextPendingRef.current = false;
|
||||||
|
|
||||||
|
// Simple check if src changed significantly (avoiding minor encoding diffs if possible, but exact match is safer)
|
||||||
|
if (currentSrc !== url) {
|
||||||
|
audio.src = url;
|
||||||
|
if (wasPlaying) {
|
||||||
|
playAudioWithFallback(audio, { deferOnIOS });
|
||||||
|
}
|
||||||
|
} else if (deferOnIOS && wasPlaying) {
|
||||||
|
playAudioWithFallback(audio, { deferOnIOS: true });
|
||||||
}
|
}
|
||||||
} else if (deferOnIOS && wasPlaying) {
|
};
|
||||||
playAudioWithFallback(audio, { deferOnIOS: true });
|
|
||||||
}
|
fetchAndPlay();
|
||||||
} else {
|
} else {
|
||||||
autoNextPendingRef.current = false;
|
autoNextPendingRef.current = false;
|
||||||
}
|
}
|
||||||
|
return () => { isMounted = false; };
|
||||||
}, [currentSong, quality]); // Re-run when quality changes
|
}, [currentSong, quality]); // Re-run when quality changes
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -1417,11 +1429,16 @@
|
|||||||
if (options.immediate) {
|
if (options.immediate) {
|
||||||
const audio = audioRef.current;
|
const audio = audioRef.current;
|
||||||
if (!audio || !nextSong) return;
|
if (!audio || !nextSong) return;
|
||||||
const url = api.getSongUrl(nextSong.id, nextSong.platform || nextSong.source, quality);
|
api.getSongUrl(nextSong.id, nextSong.platform || nextSong.source, quality).then(url => {
|
||||||
if (audio.src !== url) {
|
if (!url) return;
|
||||||
audio.src = url;
|
// Ensure we are still trying to play the same song
|
||||||
}
|
if (currentSongRef.current?.id === nextSong.id) {
|
||||||
playAudioWithFallback(audio, { deferOnIOS: options.deferOnIOS });
|
if (audio.src !== url) {
|
||||||
|
audio.src = url;
|
||||||
|
}
|
||||||
|
playAudioWithFallback(audio, { deferOnIOS: options.deferOnIOS });
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user