UNPKG

react-native-priv-sdk

Version:

Official MyCover.ai SDK. Supercharge your product with MyCover AI Insurance offerings. Create embedded insurance offerings or full white label insurance applications that excite your customers.

87 lines (75 loc) 2.84 kB
// import { Video } from 'react-native-compressor'; import type { FileData } from '../screens/purchase/form/components/CustomImagePicker'; import * as FileSystem from 'expo-file-system'; // import * as FileSystem from "expo-file-system" // import RNFS from 'react-native-fs'; export class VideoUtils { // @ts-nocheck // static async compressVideo( // fileData: FileData, // setIsInspectionLoading: (data: number) => void // ) { // try { // // const startTime = new Date().getTime(); // const compressedVideoUri = await Video.compress( // fileData.uri, // { // // progressDivider: 10, // compressionMethod: 'manual', // bitrate: 2000000, // }, // (progress) => { // const scaledProgress = Math.ceil(progress * 80); // Scale to 80 instead of 100 // setIsInspectionLoading(scaledProgress); // console.log('Compression Progress: ', scaledProgress); // } // ); // // const endTime = new Date().getTime(); // // const timeTakenInSeconds = (endTime - startTime) / 1000; // console.log('Compressed Video URI:', compressedVideoUri); // // showToast(ToastStatus.failed, `Compression Took ${timeTakenInSeconds} S`); // return compressedVideoUri; // } catch (error) { // console.error('Error compressing video:', error); // return null; // } // } static async getFileSize(fileData: FileData): Promise<number | null> { // try { // try { // // const stats = await RNFS.stat(fileData.uri); // // let fileInfo = await FileSystem.; // // return fileInfo.; // // const sizeInMB = Number(stats.size) / (1024 * 1024); // return 80; // } catch (error) { // console.error('Error fetching file size:', error); // return null; // } // } try { // Get file metadata const fileInfo = await FileSystem.getInfoAsync(fileData.uri); if (fileInfo.exists) { // File size in bytes const fileSizeInBytes = fileInfo.size; // Convert file size to a more readable format (e.g., KB, MB) const fileSizeInKB = fileSizeInBytes / 1024; const fileSizeInMB = fileSizeInKB / 1024; console.log('File size in bytes:', fileSizeInBytes); console.log('File size in KB:', fileSizeInKB); console.log('File size in MB:', fileSizeInMB); return fileSizeInMB; // Return the size in bytes } else { console.log('File does not exist.'); return null; } } catch (error) { console.error('Error fetching file size:', error); return null; } } } // Now you can call it like this: // const compressedUri = await VideoUtils.compressVideo(fileData, loadStore);