Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Unable to bridge NSNumber to Float #275

Open
krmao opened this issue Mar 6, 2024 · 1 comment
Open

Fatal error: Unable to bridge NSNumber to Float #275

krmao opened this issue Mar 6, 2024 · 1 comment

Comments

@krmao
Copy link
Contributor

krmao commented Mar 6, 2024

Current behavior

ios crash on compress video

image

Expected behavior

not crash

Platform

  • iOS

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;
Copy link

github-actions bot commented Mar 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant