From 515f87ed2487d6d875dfc6a266e47e7785e94818 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Wed, 4 Sep 2024 15:56:29 +0100 Subject: [PATCH] fail video if cannot load preview (#5138) --- src/view/com/composer/videos/VideoPreview.web.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/view/com/composer/videos/VideoPreview.web.tsx b/src/view/com/composer/videos/VideoPreview.web.tsx index e802addd..4c44781c 100644 --- a/src/view/com/composer/videos/VideoPreview.web.tsx +++ b/src/view/com/composer/videos/VideoPreview.web.tsx @@ -1,9 +1,12 @@ import React, {useEffect, useRef} from 'react' import {View} from 'react-native' import {ImagePickerAsset} from 'expo-image-picker' +import {msg} from '@lingui/macro' +import {useLingui} from '@lingui/react' import {CompressedVideo} from '#/lib/media/video/types' import {clamp} from '#/lib/numbers' +import * as Toast from '#/view/com/util/Toast' import {ExternalEmbedRemoveBtn} from 'view/com/composer/ExternalEmbedRemoveBtn' import {atoms as a} from '#/alf' @@ -19,6 +22,7 @@ export function VideoPreview({ clear: () => void }) { const ref = useRef(null) + const {_} = useLingui() useEffect(() => { if (!ref.current) return @@ -32,11 +36,19 @@ export function VideoPreview({ }, {signal}, ) + ref.current.addEventListener( + 'error', + () => { + Toast.show(_(msg`Could not process your video`)) + clear() + }, + {signal}, + ) return () => { abortController.abort() } - }, [setDimensions]) + }, [setDimensions, _, clear]) let aspectRatio = asset.width / asset.height