Start the Metro bundler
masterBefore building the app, you must start Metro, the JavaScript build tool for React Native. Run the following command from the root of the project:
# Using npm
npm start
# OR using Yarn
yarn startrepository·master·Indexed 43 days ago
https://github.com/souvik-ghosh/react-native-create-thumbnailA React Native wrapper for generating video thumbnails on iOS and Android using native APIs (AVAssetImageGenerator and MediaMetadataRetriever). Version 2.2.0 supports both local and remote video sources and includes built-in storage and cache management.
Before building the app, you must start Metro, the JavaScript build tool for React Native. Run the following command from the root of the project:
# Using npm
npm start
# OR using Yarn
yarn startIf you intend to publish this library as a Maven dependency, you must complete these steps before publishing a new version to npm:
local.properties file in the android directory to point to your Android SDK and NDK locations.maven folder to ensure a clean build.maven folder and contain the correct version number.ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle
sdk.dir=/Users/{username}/Library/Android/sdk./gradlew installArchivesFor iOS, you must first install CocoaPods dependencies.
bundle installbundle exec pod installOnce dependencies are installed, run the following command to launch the app on an iOS Simulator or connected device:
# Using npm
npm run ios
# OR using Yarn
yarn iosTo use this library in your React Native project, install it via npm or yarn and ensure native dependencies are linked.
npm i react-native-create-thumbnailor
yarn add react-native-create-thumbnailFor React Native 0.60+ (Autolinking):
cd ios && pod installFor React Native < 0.60:
react-native link react-native-create-thumbnailIf you need to perform a full reload to reset the app state, use the following platform-specific methods:
With Metro running, open a new terminal window 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 androidEnsure your Android application has the following permissions configured:
READ_EXTERNAL_STORAGEWRITE_EXTERNAL_STORAGEsdk_version < 14.Import createThumbnail to generate a thumbnail from a local or remote video file. The function returns a Promise that resolves with a response object containing the thumbnail's metadata or rejects with an error.
import { createThumbnail } from "react-native-create-thumbnail";
createThumbnail({
url: '<path to video file>',
timeStamp: 10000,
})
.then(response => console.log({ response }))
.catch(err => console.log({ err }));The Promise returned by createThumbnail resolves to an object containing the following properties:
| Property | Type | Description |
|---|---|---|
path | String | Path to generated thumbnail |
size | Number | Size (in bytes) of thumbnail |
mime | String | Mimetype of thumbnail |
width | Number | Thumbnail width |
height | Number | Thumbnail height |
The createThumbnail function accepts a request object with the following properties:
| Property | Type | Description |
|---|---|---|
url | String (required) | Path to video file (local or remote) |
timeStamp | Number (default 0) | Thumbnail timestamp (in milliseconds) |
format | String (default jpeg) | Thumbnail format: jpeg or png |
maxWidth | Number (default 512) | Max thumbnail width in px |
maxHeight | Number (default 512) | Max thumbnail height in px |
dirSize | Number (default 100) | Max cache directory size (in MB). When full, old thumbnails are deleted to clear ~half the size. |
headers | Object | Headers to load the video with (e.g., { Authorization: 'token' }) |
cacheName | String (optional) | Cache name to avoid duplicate generation. If a thumbnail with this name exists, it is returned instead of re-generating. |
timeToleranceMs | Number (default 2000, iOS only) | Time tolerance in ms for the system to pick the best matching video frame |
onlySyncedFrames | Boolean (default true, Android only) | true: retrieve a sync frame closest to timestamp. false: retrieve closest frame regardless of sync status. |
The createThumbnail function is the primary API for generating thumbnails from media files. It is exported as a named export from the package. It wraps the underlying CreateThumbnail native module.
import createThumbnail from 'react-native-create-thumbnail';
// Usage example (exact signature depends on native implementation):
// createThumbnail(requestObject).then(responseObject => ...)The entire CreateThumbnail native module can be imported as a default export. This provides access to the underlying native methods directly.
import CreateThumbnail from 'react-native-create-thumbnail';
// Accessing the module directly
console.log(CreateThumbnail);