i want to save video from instagram. I am using RNFS for it, user can download intagram videos from url and i will save them Directory path, after then i want to use that local file path with react-native-video for show it again.
Here is my code downlaoader code,
const getTimeStamp = new Date().getTime();
const fileName = RNFS.DocumentDirectoryPath + "/Reels_" + getTimeStamp + ".mp4";
const downloadResult = await RNFS.downloadFile({
fromUrl: prompt,
toFile: fileName,
background: true,
discretionary: true,
}).promise;
if (downloadResult.statusCode === 200) {
console.log(`File downloaded successfully to ${fileName}`);
setCreatedTotal(createdTotal + 1);
const parsedCreatedTotalVideos = createdTotalVideos ? JSON.parse(createdTotalVideos) : [];
parsedCreatedTotalVideos.push(fileName);
await AsyncStorage.setItem("allVideoFilePaths", JSON.stringify(parsedCreatedTotalVideos));
setIsLoading(false);
return true;
} else {
console.warn("Failed to download file. Status code:", downloadResult.statusCode);
setIsLoading(false);
return false;
}
I am using AsyncStorage for video path after usage, it is not important now after this download it throw 200 but when i tried to open video with local path (directory path) with this code ->
<Video
source={{ type: "mp4", uri: `file://${selectedVideoFilePath}` }}
style={styles.video}
controls={true}
resizeMode="contain"
onError={(e) => {
console.error("Video playback error:", e);
Alert.alert(
"Error",
"The video could not be played. Please check the file format and path."
);
}}
/>
it gives
ERROR Video playback error: {“error”: {“code”: -11829, “domain”: “AVFoundationErrorDomain”, “localizedDescription”: “Cannot Open”, “localizedFailureReason”: “This media may be damaged.”, “localizedRecoverySuggestion”: “”}, “target”: 617}
What can i do?
I tried NRFS
I tried RNFetch-blob