2022-06-05 01:34:11 +02:00
|
|
|
<script lang="ts">
|
2024-05-14 21:31:47 +02:00
|
|
|
import { loopVideo as loopVideoPreference, videoViewerVolume, videoViewerMuted } from '$lib/stores/preferences.store';
|
2024-02-14 14:09:49 +01:00
|
|
|
import { getAssetFileUrl, getAssetThumbnailUrl } from '$lib/utils';
|
2023-08-27 06:31:52 +02:00
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
2024-02-14 15:38:57 +01:00
|
|
|
import { ThumbnailFormat } from '@immich/sdk';
|
2024-02-14 14:09:49 +01:00
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
import { fade } from 'svelte/transition';
|
|
|
|
import LoadingSpinner from '../shared-components/loading-spinner.svelte';
|
2022-06-05 01:34:11 +02:00
|
|
|
|
2023-07-01 06:50:47 +02:00
|
|
|
export let assetId: string;
|
2024-05-14 21:31:47 +02:00
|
|
|
export let loopVideo: boolean;
|
2024-05-24 02:26:22 +02:00
|
|
|
export let checksum: string;
|
2022-06-05 01:34:11 +02:00
|
|
|
|
2024-03-21 21:01:08 +01:00
|
|
|
let element: HTMLVideoElement | undefined = undefined;
|
2023-07-01 06:50:47 +02:00
|
|
|
let isVideoLoading = true;
|
2024-05-24 02:26:22 +02:00
|
|
|
let assetFileUrl: string;
|
|
|
|
|
|
|
|
$: {
|
|
|
|
const next = getAssetFileUrl(assetId, false, true, checksum);
|
|
|
|
if (assetFileUrl !== next) {
|
|
|
|
assetFileUrl = next;
|
|
|
|
element && element.load();
|
|
|
|
}
|
|
|
|
}
|
2024-03-21 21:01:08 +01:00
|
|
|
|
2023-08-26 01:20:45 +02:00
|
|
|
const dispatch = createEventDispatcher<{ onVideoEnded: void; onVideoStarted: void }>();
|
2022-06-05 01:34:11 +02:00
|
|
|
|
2023-08-17 17:02:12 +02:00
|
|
|
const handleCanPlay = async (event: Event) => {
|
|
|
|
try {
|
|
|
|
const video = event.currentTarget as HTMLVideoElement;
|
|
|
|
await video.play();
|
2023-08-26 01:20:45 +02:00
|
|
|
dispatch('onVideoStarted');
|
2023-08-17 17:02:12 +02:00
|
|
|
} catch (error) {
|
2024-02-27 17:37:37 +01:00
|
|
|
handleError(error, 'Unable to play video');
|
2023-08-17 20:52:50 +02:00
|
|
|
} finally {
|
|
|
|
isVideoLoading = false;
|
2023-08-17 17:02:12 +02:00
|
|
|
}
|
2023-07-01 06:50:47 +02:00
|
|
|
};
|
2022-06-05 01:34:11 +02:00
|
|
|
</script>
|
|
|
|
|
2024-04-14 04:41:00 +02:00
|
|
|
<div
|
|
|
|
transition:fade={{ duration: 150 }}
|
|
|
|
class="flex select-none place-content-center place-items-center"
|
|
|
|
style="height: calc(100% - 64px)"
|
|
|
|
>
|
2023-07-01 06:50:47 +02:00
|
|
|
<video
|
2024-03-21 21:01:08 +01:00
|
|
|
bind:this={element}
|
2024-05-14 21:31:47 +02:00
|
|
|
loop={$loopVideoPreference && loopVideo}
|
2023-08-17 20:52:50 +02:00
|
|
|
autoplay
|
|
|
|
playsinline
|
2023-07-01 06:50:47 +02:00
|
|
|
controls
|
|
|
|
class="h-full object-contain"
|
|
|
|
on:canplay={handleCanPlay}
|
|
|
|
on:ended={() => dispatch('onVideoEnded')}
|
2024-05-10 22:28:21 +02:00
|
|
|
bind:muted={$videoViewerMuted}
|
2023-07-01 06:50:47 +02:00
|
|
|
bind:volume={$videoViewerVolume}
|
2024-05-24 02:26:22 +02:00
|
|
|
poster={getAssetThumbnailUrl(assetId, ThumbnailFormat.Jpeg, checksum)}
|
2023-07-01 06:50:47 +02:00
|
|
|
>
|
2024-05-24 02:26:22 +02:00
|
|
|
<source src={assetFileUrl} type="video/mp4" />
|
2023-07-01 06:50:47 +02:00
|
|
|
<track kind="captions" />
|
|
|
|
</video>
|
2023-02-15 18:56:19 +01:00
|
|
|
|
2023-07-01 06:50:47 +02:00
|
|
|
{#if isVideoLoading}
|
2023-07-18 20:19:39 +02:00
|
|
|
<div class="absolute flex place-content-center place-items-center">
|
2023-07-01 06:50:47 +02:00
|
|
|
<LoadingSpinner />
|
|
|
|
</div>
|
|
|
|
{/if}
|
2022-06-05 01:34:11 +02:00
|
|
|
</div>
|