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