Browse Source

Get first frame of video as thumbnail

Hau Vo 7 years ago
parent
commit
9bf436bf64
2 changed files with 6 additions and 2 deletions
  1. 5
    1
      android/src/main/java/com/reactlibrary/RNThumbnailModule.java
  2. 1
    1
      package.json

+ 5
- 1
android/src/main/java/com/reactlibrary/RNThumbnailModule.java View File

14
 import android.graphics.Bitmap;
14
 import android.graphics.Bitmap;
15
 import android.os.Environment;
15
 import android.os.Environment;
16
 import android.util.Log;
16
 import android.util.Log;
17
+import android.media.MediaMetadataRetriever;
17
 import java.util.UUID;
18
 import java.util.UUID;
18
 import java.io.File;
19
 import java.io.File;
19
 import java.io.OutputStream;
20
 import java.io.OutputStream;
36
   @ReactMethod
37
   @ReactMethod
37
   public void get(String filePath, Promise promise) {
38
   public void get(String filePath, Promise promise) {
38
     filePath = filePath.replace("file://","");
39
     filePath = filePath.replace("file://","");
39
-    Bitmap image = ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MINI_KIND);
40
+    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
41
+    retriever.setDataSource(filePath);
42
+    Bitmap image = retriever.getFrameAtTime(1000000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
43
+
40
     String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath();
44
     String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath();
41
 
45
 
42
     try {
46
     try {

+ 1
- 1
package.json View File

1
 
1
 
2
 {
2
 {
3
   "name": "react-native-thumbnail",
3
   "name": "react-native-thumbnail",
4
-  "version": "1.0.2",
4
+  "version": "1.0.3",
5
   "description": "",
5
   "description": "",
6
   "main": "index.js",
6
   "main": "index.js",
7
   "scripts": {
7
   "scripts": {