Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
souvik-ghosh committed Apr 19, 2020
1 parent d1b92ba commit 03d172b
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 122 deletions.
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,11 @@ iOS/Android thumbnail generator with support for both local and remote videos. `
import { createThumbnail } from "react-native-create-thumbnail";
createThumbnail({
url: "<path to video file>",
type: "local"
timeStamp: 5
url: '<path to video file>',
timeStamp: 10000,
type: 'local'
})
.then(response => {
console.log({ response });
this.setState({
status: "Thumbnail received",
thumbnail: response.path
});
})
.then(response => console.log({ response }));
.catch(err => console.log({ err }));
```
Expand All @@ -58,9 +52,10 @@ createThumbnail({
| Property | Type | Description |
| --------- | :-------------------------: | :------------------------------------------------- |
| url | `String` (required) | Path to video file (local or remote) |
| timeStamp | `Number` (default `1`) | Thumbnail timestamp (in seconds) |
| timeStamp | `Number` (default `0`) | Thumbnail timestamp (in milliseconds) |
| type | `String` (default `remote`) | Resource type, can be one of: `remote`, or `local` |
| format | `String` (default `jpeg`) | Thumbnail format, can be one of: `jpeg`, or `png` |
| dirSize | `Number` (default `100`) | Maximum size of the cache directory (in megabytes) |
## Response Object
Expand All @@ -80,7 +75,8 @@ READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE
#### Limitations
Remote videos aren't supported on android sdk_version < 14
- Remote videos aren't supported on android sdk_version < 14.
- This is a **Native Module**, so it won't work in expo managed projects.
#### Credits
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def configureReactNativePom(def pom) {
name packageJson.title
artifactId packageJson.name
version = packageJson.version
group = "com.reactlibrary"
group = "com.reactlibrary.createthumbnail"
description packageJson.description
url packageJson.repository.baseUrl

Expand Down
2 changes: 1 addition & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reactlibrary">
package="com.reactlibrary.createthumbnail">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.reactlibrary;
package com.reactlibrary.createthumbnail;

import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -25,7 +25,6 @@
public class CreateThumbnailModule extends ReactContextBaseJavaModule {

private final ReactApplicationContext reactContext;
private static final long CACHE_DIR_MAX_SIZE = 104857600L; // 100MB

public CreateThumbnailModule(ReactApplicationContext reactContext) {
super(reactContext);
Expand All @@ -42,10 +41,12 @@ public void create(ReadableMap options, Promise promise) {
String filePath = options.hasKey("url") ? options.getString("url") : "";
String type = options.hasKey("type") ? options.getString("type") : "remote";
String format = options.hasKey("format") ? options.getString("format") : "jpeg";
int timeStamp = options.hasKey("timeStamp") ? options.getInt("timeStamp") : 1;
int timeStamp = options.hasKey("timeStamp") ? options.getInt("timeStamp") : 0;
int dirSize = options.hasKey("dirSize") ? options.getInt("dirSize") : 100;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
String thumbnailDir = reactContext.getApplicationContext().getCacheDir().getAbsolutePath() + "/thumbnails";
String fileName = "thumb-" + UUID.randomUUID().toString() + "." + format;
long cacheDirSize = dirSize * 1024 * 1024;
OutputStream fOut = null;

try {
Expand All @@ -54,17 +55,20 @@ public void create(ReadableMap options, Promise promise) {
retriever.setDataSource(filePath);
} else {
if (VERSION.SDK_INT < 14) {
throw new IllegalStateException("remote videos aren't supported on sdk_version < 14");
throw new IllegalStateException("Remote videos aren't supported on sdk_version < 14");
}
retriever.setDataSource(filePath, new HashMap<String, String>());
}

Bitmap image = retriever.getFrameAtTime(timeStamp * 1000000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
Bitmap image = retriever.getFrameAtTime(timeStamp * 1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
retriever.release();

File dir = new File(thumbnailDir);
if (!dir.exists()) {
dir.mkdirs();
// Add .nomedia to hide the thumbnail directory from gallery
File noMedia = new File(thumbnailDir, ".nomedia");
file.createNewFile();
}

File file = new File(thumbnailDir, fileName);
Expand All @@ -84,8 +88,8 @@ public void create(ReadableMap options, Promise promise) {

long newSize = image.getByteCount() + getDirSize(dir);
// free up some cached data if size of cache dir exceeds CACHE_DIR_MAX_SIZE
if (newSize > CACHE_DIR_MAX_SIZE) {
cleanDir(dir, CACHE_DIR_MAX_SIZE / 2);
if (newSize > cacheDirSize) {
cleanDir(dir, cacheDirSize / 2);
}

WritableMap map = Arguments.createMap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.reactlibrary;
package com.reactlibrary.createthumbnail;

import java.util.Arrays;
import java.util.Collections;
Expand Down
5 changes: 2 additions & 3 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ export default class App extends Component {

componentDidMount() {
createThumbnail({
url:
"https://uc8d882487c3bc5496dba3acd6ea.dl.dropboxusercontent.com/cd/0/get/At30lKs23Exff289oyuORmbjN1WgY0gVvQplB1PUw3Z9AMej2kWdCAR3MAq0BJ8krvYVhp0PjEEh0abLvi3qjUnZW8PxyM-Y7KiA9WaihEeVT7TPCZ400ZbNBofzyaL46T8/file?dl=1",
timeStamp: 10
url: 'https://www.example.com/video-file.mp4',
timeStamp: 10000
})
.then(response => {
console.log({ response });
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ PODS:
- React-cxxreact (= 0.61.5)
- React-jsi (= 0.61.5)
- React-jsinspector (0.61.5)
- react-native-create-thumbnail (1.0.0):
- react-native-create-thumbnail (1.1.0):
- React
- React-RCTActionSheet (0.61.5):
- React-Core/RCTActionSheetHeaders (= 0.61.5)
Expand Down Expand Up @@ -253,7 +253,7 @@ DEPENDENCIES:
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
https://github.com/CocoaPods/Specs.git:
- boost-for-react-native

EXTERNAL SOURCES:
Expand Down Expand Up @@ -326,7 +326,7 @@ SPEC CHECKSUMS:
React-jsi: cb2cd74d7ccf4cffb071a46833613edc79cdf8f7
React-jsiexecutor: d5525f9ed5f782fdbacb64b9b01a43a9323d2386
React-jsinspector: fa0ecc501688c3c4c34f28834a76302233e29dc0
react-native-create-thumbnail: 529eb6806df44beefe322bec753c1452f0093a81
react-native-create-thumbnail: 056455814fe07dc68a4d8051601724e5785a7127
React-RCTActionSheet: 600b4d10e3aea0913b5a92256d2719c0cdd26d76
React-RCTAnimation: 791a87558389c80908ed06cc5dfc5e7920dfa360
React-RCTBlob: d89293cc0236d9cb0933d85e430b0bbe81ad1d72
Expand All @@ -341,4 +341,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 79310af6b976c356911a8a833e9b99c3399fdda3

COCOAPODS: 1.7.5
COCOAPODS: 1.8.4
Loading

0 comments on commit 03d172b

Please sign in to comment.