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 React, {useEffect, useRef} from 'react'
import {View} from 'react-native' import {View} from 'react-native'
import {ImagePickerAsset} from 'expo-image-picker' import {ImagePickerAsset} from 'expo-image-picker'
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {CompressedVideo} from '#/lib/media/video/types' import {CompressedVideo} from '#/lib/media/video/types'
import {clamp} from '#/lib/numbers' import {clamp} from '#/lib/numbers'
import * as Toast from '#/view/com/util/Toast'
import {ExternalEmbedRemoveBtn} from 'view/com/composer/ExternalEmbedRemoveBtn' import {ExternalEmbedRemoveBtn} from 'view/com/composer/ExternalEmbedRemoveBtn'
import {atoms as a} from '#/alf' import {atoms as a} from '#/alf'
@ -19,6 +22,7 @@ export function VideoPreview({
clear: () => void clear: () => void
}) { }) {
const ref = useRef<HTMLVideoElement>(null) const ref = useRef<HTMLVideoElement>(null)
const {_} = useLingui()
useEffect(() => { useEffect(() => {
if (!ref.current) return if (!ref.current) return
@ -32,11 +36,19 @@ export function VideoPreview({
}, },
{signal}, {signal},
) )
ref.current.addEventListener(
'error',
() => {
Toast.show(_(msg`Could not process your video`))
clear()
},
{signal},
)
return () => { return () => {
abortController.abort() abortController.abort()
} }
}, [setDimensions]) }, [setDimensions, _, clear])
let aspectRatio = asset.width / asset.height let aspectRatio = asset.width / asset.height