numandev1 / react-native-compressor

🗜️Compress Image, Video, and Audio same like Whatsapp 🚀✨
MIT License
949 stars 93 forks source link

Fatal error: Unable to bridge NSNumber to Float #275

Open krmao opened 8 months ago

krmao commented 8 months ago

Current behavior

ios crash on compress video

image

Expected behavior

not crash

Platform

React Native Version

0.72.4

React Native Compressor Version

1.8.24

Reproducible Steps And Demo

/**
 * https://github.com/numandev1/react-native-compressor/issues/217#issuecomment-1807184218
 * @param fileUrl
 * @param compressVideoQuality
 */
const compressVideo = async (fileUrl: string, compressVideoQuality = 0.85): Promise<string> => {
  const originalVideoMetada = (await getVideoMetaData(fileUrl)) as any;
  const originalBitrate: number = originalVideoMetada.size / ((originalVideoMetada.duration / 60) * 0.0075); // sizeInKb / (minutes * 0.0075)
  const targetBitrate: number = Math.round(originalBitrate * compressVideoQuality);
  return await Video.compress(
    fileUrl,
    {
      progressDivider: 20,
      maxSize: 720,
      bitrate: targetBitrate,
      compressionMethod: 'manual',
      downloadProgress: progress => {
        console.log('> compressVideo download progress: ', progress);
      },
    },
    progress => {
      console.log('> compressVideo compress progress: ', progress);
    },
  );
};

Quick fix

change

var bitRate=options["bitrate"] as! Float?;

to

var bitRate = (options["bitrate"] as? NSNumber)?.floatValue;
github-actions[bot] commented 8 months ago

👋 @krmao Thanks for opening your issue here! If you find this package useful hit the star🌟!