mirror of
https://github.com/immich-app/immich.git
synced 2025-01-07 00:50:23 -05:00
refactor(web): harden video can play method (#3745)
This commit is contained in:
parent
ce84f9c755
commit
8ba338fbe1
1 changed files with 12 additions and 8 deletions
|
@ -4,21 +4,25 @@
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
import { videoViewerVolume } from '$lib/stores/preferences.store';
|
import { videoViewerVolume } from '$lib/stores/preferences.store';
|
||||||
import LoadingSpinner from '../shared-components/loading-spinner.svelte';
|
import LoadingSpinner from '../shared-components/loading-spinner.svelte';
|
||||||
|
import { handleError } from '../../utils/handle-error';
|
||||||
|
|
||||||
export let assetId: string;
|
export let assetId: string;
|
||||||
export let publicSharedKey: string | undefined = undefined;
|
export let publicSharedKey: string | undefined = undefined;
|
||||||
|
|
||||||
let isVideoLoading = true;
|
let isVideoLoading = true;
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher<{ onVideoEnded: void }>();
|
||||||
|
|
||||||
const handleCanPlay = (ev: Event & { currentTarget: HTMLVideoElement }) => {
|
const handleCanPlay = async (event: Event) => {
|
||||||
const playerNode = ev.currentTarget;
|
try {
|
||||||
|
const video = event.currentTarget as HTMLVideoElement;
|
||||||
|
video.muted = true;
|
||||||
|
await video.play();
|
||||||
|
video.muted = false;
|
||||||
|
|
||||||
playerNode.muted = true;
|
isVideoLoading = false;
|
||||||
playerNode.play();
|
} catch (error) {
|
||||||
playerNode.muted = false;
|
handleError(error, 'Unable to play video');
|
||||||
|
}
|
||||||
isVideoLoading = false;
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue