|
@@ -28,6 +28,8 @@ const RenderMessageVideo = ({
|
|
|
const [isBuffering, setIsBuffering] = useState(true);
|
|
|
const [videoUri, setVideoUri] = useState<string | null>(null);
|
|
|
const [isVideoLoaded, setIsVideoLoaded] = useState(false);
|
|
|
+ const [retryCount, setRetryCount] = useState(0);
|
|
|
+ const MAX_RETRY = 3;
|
|
|
|
|
|
const downloadVideo = async (videoUrl: string) => {
|
|
|
if (!videoUrl.startsWith('https')) {
|
|
@@ -46,9 +48,20 @@ const RenderMessageVideo = ({
|
|
|
|
|
|
const videoExists = await FileSystem.getInfoAsync(videoPath);
|
|
|
if (videoExists.exists) {
|
|
|
- setVideoUri(videoPath);
|
|
|
- setIsVideoLoaded(true);
|
|
|
- return videoPath;
|
|
|
+ if (videoExists.size < 1024) {
|
|
|
+ await FileSystem.deleteAsync(videoPath, { idempotent: true });
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ await FileSystem.readAsStringAsync(videoPath, {
|
|
|
+ encoding: FileSystem.EncodingType.Base64
|
|
|
+ });
|
|
|
+ setVideoUri(videoPath);
|
|
|
+ setIsVideoLoaded(true);
|
|
|
+ return videoPath;
|
|
|
+ } catch (e) {
|
|
|
+ await FileSystem.deleteAsync(videoPath, { idempotent: true });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const downloadResult = await FileSystem.downloadAsync(videoUrl, videoPath, {
|
|
@@ -118,6 +131,21 @@ const RenderMessageVideo = ({
|
|
|
posterStyle={{ resizeMode: 'cover', width: '100%', height: '100%' }}
|
|
|
usePoster={true}
|
|
|
posterSource={{ uri: API_HOST + currentMessage.attachment.attachment_small_url }}
|
|
|
+ onError={async () => {
|
|
|
+ if (retryCount >= MAX_RETRY) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (videoUri) {
|
|
|
+ await FileSystem.deleteAsync(videoUri, { idempotent: true });
|
|
|
+
|
|
|
+ const newUri = await downloadVideo(currentMessage.video);
|
|
|
+ if (newUri) {
|
|
|
+ setVideoUri(newUri);
|
|
|
+ setRetryCount(retryCount + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }}
|
|
|
/>
|
|
|
) : null}
|
|
|
|