react-native-video-trim 5.0.2 → 5.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,10 @@
1
1
  package com.videotrim.utils;
2
2
 
3
3
  import android.media.MediaMetadataRetriever;
4
+ import android.net.Uri;
4
5
  import android.util.Log;
5
6
 
7
+ import java.io.File;
6
8
  import java.io.IOException;
7
9
  import java.util.HashMap;
8
10
 
@@ -17,7 +19,22 @@ public class MediaMetadataUtil {
17
19
  if (source.startsWith("http://") || source.startsWith("https://")) {
18
20
  retriever.setDataSource(source, new HashMap<>());
19
21
  } else {
20
- retriever.setDataSource(source);
22
+ String filePath = source;
23
+
24
+ // if "source" is not a valid file path, try to parse it as a URI
25
+ if (!StorageUtil.isFileExists(filePath)) {
26
+ Log.e(TAG, "File does not exist, trying to parse as URI: " + source);
27
+
28
+ Uri uri = Uri.parse(source);
29
+ filePath = uri.getPath();
30
+
31
+ if (!StorageUtil.isFileExists(filePath)) {
32
+ Log.e(TAG, "File does not exist at path: " + filePath);
33
+ return null;
34
+ }
35
+ }
36
+
37
+ retriever.setDataSource(filePath);
21
38
  }
22
39
  return retriever;
23
40
  } catch (Exception e) {
@@ -27,6 +27,12 @@ public class StorageUtil {
27
27
  return file.getAbsolutePath();
28
28
  }
29
29
 
30
+ public static boolean isFileExists(String filePath) {
31
+ if (TextUtils.isEmpty(filePath)) return false;
32
+ File file = new File(filePath);
33
+ return file.exists();
34
+ }
35
+
30
36
  public static String[] listFiles(Context context) {
31
37
  File filesDir = context.getFilesDir();
32
38
  File[] files = filesDir.listFiles((dir, name) -> name.startsWith(VideoTrimmerUtil.FILE_PREFIX));
@@ -270,7 +270,7 @@ public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
270
270
 
271
271
  VideoTrimmerUtil.SCREEN_WIDTH_FULL = this.getScreenWidthInPortraitMode();
272
272
  VideoTrimmerUtil.VIDEO_FRAMES_WIDTH = VideoTrimmerUtil.SCREEN_WIDTH_FULL - RECYCLER_VIEW_PADDING * 2;
273
- VideoTrimmerUtil.MAX_COUNT_RANGE = Math.max((VIDEO_FRAMES_WIDTH / VideoTrimmerUtil.mThumbWidth), VideoTrimmerUtil.MAX_COUNT_RANGE);
273
+ VideoTrimmerUtil.MAX_COUNT_RANGE = VideoTrimmerUtil.mThumbWidth != 0 ? Math.max((VIDEO_FRAMES_WIDTH / VideoTrimmerUtil.mThumbWidth), VideoTrimmerUtil.MAX_COUNT_RANGE) : VideoTrimmerUtil.MAX_COUNT_RANGE;
274
274
 
275
275
  startShootVideoThumbs(mContext, VideoTrimmerUtil.MAX_COUNT_RANGE, 0, mDuration);
276
276
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-video-trim",
3
- "version": "5.0.2",
3
+ "version": "5.0.3",
4
4
  "description": "Video trimmer for your React Native app",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",