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,6 +14,7 @@ import android.provider.MediaStore.Video.Thumbnails;
14 14
 import android.graphics.Bitmap;
15 15
 import android.os.Environment;
16 16
 import android.util.Log;
17
+import android.media.MediaMetadataRetriever;
17 18
 import java.util.UUID;
18 19
 import java.io.File;
19 20
 import java.io.OutputStream;
@@ -36,7 +37,10 @@ public class RNThumbnailModule extends ReactContextBaseJavaModule {
36 37
   @ReactMethod
37 38
   public void get(String filePath, Promise promise) {
38 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 44
     String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath();
41 45
 
42 46
     try {

+ 1
- 1
package.json View File

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