Wait until full page load

This commit is contained in:
Josh Patra
2025-04-20 13:18:28 -04:00
parent 90c384d61e
commit 4ea37dc3e2

View File

@@ -232,17 +232,23 @@
countdownInterval = setInterval(updateTime, 1000); countdownInterval = setInterval(updateTime, 1000);
widget = SC.Widget(iframeElement); widget = SC.Widget(iframeElement);
// wait for full page load (or you could just use setTimeout)
window.addEventListener('load', () => {
widget.bind(SC.Widget.Events.READY, () => { widget.bind(SC.Widget.Events.READY, () => {
widget.getDuration((d: number) => (fullDuration = d)); widget.getDuration((d: number) => (fullDuration = d));
widget.getCurrentSound((sound: any) => { widget.getCurrentSound((sound: any) => {
artworkUrl = sound.artwork_url || ''; artworkUrl = sound.artwork_url || '';
}); });
// preload silently:
// give SC widget 2s to settle on Netlify before probing
setTimeout(() => {
widget.play(); widget.play();
widget.pause(); widget.pause();
widget.seekTo(0); widget.seekTo(0);
loading = false; loading = false;
widgetReady = true; widgetReady = true;
}, 2000);
});
}); });
widget.bind(SC.Widget.Events.PLAY, () => { widget.bind(SC.Widget.Events.PLAY, () => {