Start the Metro bundler
mainBefore building your app, you must start Metro, the JavaScript build tool for React Native. Run this command from the root of your project:
# Using npm
npm start
# OR using Yarn
yarn startrepository·main·Indexed 23 days ago
https://github.com/numandev1/react-native-compressorA lightweight React Native package for compressing images, videos, and audio files with quality similar to WhatsApp. It provides automatic and manual compression methods, background upload support (PUT/POST/MULTIPART), file downloading, and video thumbnail generation. Version 2.0.3 adds minimal overhead (~50KB to APK size) compared to FFmpeg and supports both React Native CLI and Managed Expo projects.
Before building your app, you must start Metro, the JavaScript build tool for React Native. Run this command from the root of your project:
# Using npm
npm start
# OR using Yarn
yarn startInstall using yarn:
yarn add react-native-compressorNote: Automatic linking is supported for React Native >= 0.60 for both Android and iOS.
For React Native <= 0.59, you must link manually:
react-native link react-native-compressorIf automatic linking fails, follow these steps for Android:
Modify MainActivity.java:
import com.reactnativecompressor.CompressorPackage; to the imports.new CompressorPackage() to the list returned by the getPackages() method.Modify android/settings.gradle:
Append these lines:
include ':react-native-compressor'
project(':react-native-compressor').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-compressor/android')Modify android/app/build.gradle:
Insert this line inside the dependencies block:
compile project(':react-native-compressor')If automatic linking fails, follow these steps for iOS:
Podfile in Xcode.pod 'react-native-compressor', :path => '../node_modules/react-native-compressor'.pod install inside the ios folder.If you want to clear the existing example code and start with a blank project structure, run the following command:
npm run reset-projectThis will move the current starter code into the app-example directory and create a fresh, empty app directory for your own development.
To run the provided Expo example project, follow these steps:
Install the project dependencies:
npm installStart the Expo development server:
npx expo startOnce the server is running, you can open the app in a development build, an Android emulator, an iOS simulator, or Expo Go.
npm install
npx expo startFor iOS, you must first install CocoaPods dependencies. If this is your first time or you have updated native dependencies, run bundle exec pod install. Then, run the following command to launch the app on an iOS Simulator or connected device:
# Install CocoaPods dependencies
bundle exec pod install
# Using npm
npm run ios
# OR using Yarn
yarn iosIf you need to forcefully reload the app to reset its state, use the following platform-specific shortcuts:
To use react-native-compressor in a Managed Expo project, follow these steps:
expo install react-native-compressorapp.json, app.config.json, or app.config.js):{
"name": "my app",
"plugins": ["react-native-compressor"]
}expo prebuildeas buildWith Metro running, open a new terminal and run the following command to build and launch the app on an Android Emulator or connected device:
# Using npm
npm run android
# OR using Yarn
yarn androidUse the Audio module to compress audio files. You can use preset quality levels or manual bitrate/samplerate settings.
import { Audio } from 'react-native-compressor';
const result = await Audio.compress(
'file://path_of_file/file_example_MP3_2MG.wav',
{ quality: 'medium' }
);import { Audio } from 'react-native-compressor';
const result = await Audio.compress(
'file://path_of_file/file_example_MP3_2MG.wav',
{
bitrate: 64000,
samplerate: 44100,
channels: 1,
}
);Use generateFilePath to create a random file path within the cache directory for saving files.
import { generateFilePath } from 'react-native-compressor';
const randomFilePath = await generateFilePath('mp4'); // file://file_path.mp4import { generateFilePath } from 'react-native-compressor';
const randomFilePathForSaveFile = await generateFilePath('mp4'); // file://file_path.mp4