diff --git a/immichFrame.Web/src/lib/components/elements/asset.svelte b/immichFrame.Web/src/lib/components/elements/asset.svelte index 14ee6465..92679fd2 100644 --- a/immichFrame.Web/src/lib/components/elements/asset.svelte +++ b/immichFrame.Web/src/lib/components/elements/asset.svelte @@ -9,6 +9,7 @@ import { thumbHashToDataURL } from 'thumbhash'; import AssetInfo from '$lib/components/elements/asset-info.svelte'; import ImageOverlay from '$lib/components/elements/imageoverlay/image-overlay.svelte'; + import { onDestroy } from 'svelte'; interface Props { asset: [url: string, asset: AssetResponseDto, albums: AlbumResponseDto[]]; @@ -184,6 +185,18 @@ } } }; + + let isDestroyed = false; + + onDestroy(() => { + isDestroyed = true; + if (videoElement) { + videoElement.pause(); + videoElement.src = ''; + videoElement.removeAttribute('src'); + videoElement.load(); + } + }); {#if showInfo} @@ -246,9 +259,12 @@ } } }} - onerror={() => console.error('Video failed to load:', asset[0])} - onwaiting={onVideoWaiting} - onplaying={onVideoPlaying} + onwaiting={() => { + if (!isDestroyed) onVideoWaiting(); + }} + onplaying={() => { + if (!isDestroyed) onVideoPlaying(); + }} > {:else} = Promise.resolve(); + const handleDone = async (previous: boolean = false, instant: boolean = false) => { - if (isHandlingAssetTransition) { - return; - } - isHandlingAssetTransition = true; - try { - userPaused = false; - progressBar.restart(false); - $instantTransition = instant; - if (previous) await getPreviousAssets(); - else await getNextAssets(); - await tick(); - await assetComponent?.play?.(); - progressBar.play(); - } finally { - isHandlingAssetTransition = false; - } + transitionLock = transitionLock + .then(async () => { + userPaused = false; + progressBar.restart(false); + $instantTransition = instant; + if (previous) await getPreviousAssets(); + else await getNextAssets(); + await tick(); + await assetComponent?.play?.(); + progressBar.play(); + }) + .catch((err) => { + console.error('handleDone transition failed:', err); + }); + await transitionLock; }; async function getNextAssets() {