fail video if cannot load preview (#5138)

zio/stable
Samuel Newman 2024-09-04 15:56:29 +01:00 committed by GitHub
parent 3eef62d995
commit 515f87ed24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 1 deletions

View File

@ -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<HTMLVideoElement>(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