react-native-video-trim 1.0.23 → 2.0.0

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.
Files changed (29) hide show
  1. package/README.md +22 -0
  2. package/android/src/main/AndroidManifest.xml +2 -0
  3. package/android/src/main/java/com/videotrim/VideoTrimModule.java +17 -2
  4. package/android/src/main/java/com/videotrim/interfaces/VideoTrimListener.java +5 -1
  5. package/android/src/main/java/com/videotrim/utils/VideoTrimmerUtil.java +38 -3
  6. package/android/src/main/java/com/videotrim/widgets/VideoTrimmerView.java +406 -295
  7. package/android/src/main/res/drawable/chevron_compact_left.xml +15 -0
  8. package/android/src/main/res/drawable/chevron_compact_right.xml +15 -0
  9. package/android/src/main/res/drawable/chevron_right_with_bg.xml +13 -0
  10. package/android/src/main/res/drawable/pause_fill.xml +15 -0
  11. package/android/src/main/res/drawable/play_fill.xml +15 -0
  12. package/android/src/main/res/drawable/rounded_progress_indicator.xml +16 -0
  13. package/android/src/main/res/drawable/rounded_yellow_left_background.xml +8 -0
  14. package/android/src/main/res/drawable/rounded_yellow_right_background.xml +8 -0
  15. package/android/src/main/res/drawable/yellow_border.xml +9 -0
  16. package/android/src/main/res/layout/video_trimmer_view.xml +148 -76
  17. package/android/src/main/res/values/colors.xml +15 -13
  18. package/ios/VideoTrim.swift +41 -5
  19. package/ios/VideoTrimmerViewController.swift +1 -1
  20. package/package.json +1 -1
  21. package/android/src/main/java/com/videotrim/adapters/VideoTrimmerAdapter.java +0 -54
  22. package/android/src/main/java/com/videotrim/widgets/RangeSeekBarView.java +0 -534
  23. package/android/src/main/java/com/videotrim/widgets/SpacesItemDecoration2.java +0 -33
  24. package/android/src/main/java/com/videotrim/widgets/ZVideoView.java +0 -48
  25. package/android/src/main/res/drawable/ic_video_pause_black.png +0 -0
  26. package/android/src/main/res/drawable/ic_video_play_black.png +0 -0
  27. package/android/src/main/res/drawable/ic_video_thumb_handle.png +0 -0
  28. package/android/src/main/res/drawable/icon_seek_bar.png +0 -0
  29. package/android/src/main/res/layout/video_thumb_item_layout.xml +0 -16
package/README.md CHANGED
@@ -226,6 +226,16 @@ useEffect(() => {
226
226
  console.log('onError', event);
227
227
  break;
228
228
  }
229
+ case 'onLog': {
230
+ // FFMPEG logs (while trimming)
231
+ console.log('onLog', event);
232
+ break;
233
+ }
234
+ case 'onStatistics': {
235
+ // FFMPEG stats (while trimming)
236
+ console.log('onStatistics', event);
237
+ break;
238
+ }
229
239
  }
230
240
  });
231
241
 
@@ -264,6 +274,18 @@ FFMPEGKIT_PACKAGE_VERSION=5.1 npx pod-install ios
264
274
  FFMPEGKIT_PACKAGE=full FFMPEGKIT_PACKAGE_VERSION=5.1 npx pod-install ios
265
275
  ```
266
276
 
277
+ # Android: update SDK version
278
+ You can override sdk version to use any version in your `android/build.gradle` > `buildscript` > `ext`
279
+ ```gradle
280
+ buildscript {
281
+ ext {
282
+ VideoTrim_compileSdkVersion = 34
283
+ VideoTrim_minSdkVersion = 26
284
+ VideoTrim_targetSdkVersion = 34
285
+ }
286
+ }
287
+ ```
288
+
267
289
  # Thanks
268
290
  - Android part is created by modified + fix bugs from: https://github.com/iknow4/Android-Video-Trimmer
269
291
  - iOS UI is created from: https://github.com/AndreasVerhoeven/VideoTrimmerControl
@@ -1,2 +1,4 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.videotrim">
2
+
3
+ <uses-permission android:name="android.permission.VIBRATE" />
2
4
  </manifest>
@@ -147,7 +147,6 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
147
147
  public void onHostPause() {
148
148
  if (trimmerView != null) {
149
149
  trimmerView.onVideoPause();
150
- trimmerView.setRestoreState(true);
151
150
  }
152
151
  }
153
152
 
@@ -164,6 +163,11 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
164
163
  }
165
164
 
166
165
  @Override public void onTrimmingProgress(int percentage) {
166
+ // prevent onTrimmingProgress is called after onFinishTrim (some rare cases)
167
+ if (mProgressBar == null) {
168
+ return;
169
+ }
170
+
167
171
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
168
172
  mProgressBar.setProgress(percentage, true);
169
173
  } else {
@@ -172,10 +176,13 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
172
176
  }
173
177
 
174
178
 
175
- @Override public void onFinishTrim(String in) {
179
+ @Override public void onFinishTrim(String in, long startTime, long endTime, int duration) {
176
180
  runOnUiThread(() -> {
177
181
  WritableMap map = Arguments.createMap();
178
182
  map.putString("outputPath", in);
183
+ map.putInt("duration", duration);
184
+ map.putDouble("startTime", (double) startTime);
185
+ map.putDouble("endTime", (double) endTime);
179
186
  sendEvent(getReactApplicationContext(), "onFinishTrimming", map);
180
187
  showEditorPromise.resolve(in);
181
188
  });
@@ -232,6 +239,14 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
232
239
  alertDialog.show();
233
240
  }
234
241
 
242
+ @Override public void onLog(WritableMap log) {
243
+ sendEvent(getReactApplicationContext(), "onLog", log);
244
+ }
245
+
246
+ @Override public void onStatistics(WritableMap statistics) {
247
+ sendEvent(getReactApplicationContext(), "onStatistics", statistics);
248
+ }
249
+
235
250
  @ReactMethod
236
251
  private void hideDialog() {
237
252
  if (mProgressDialog != null) {
@@ -1,10 +1,14 @@
1
1
  package com.videotrim.interfaces;
2
2
 
3
+ import com.facebook.react.bridge.WritableMap;
4
+
3
5
  public interface VideoTrimListener {
4
6
  void onStartTrim();
5
7
  void onTrimmingProgress(int percentage);
6
- void onFinishTrim(String url);
8
+ void onFinishTrim(String url, long startMs, long endMs, int videoDuration);
7
9
  void onError(String errorMessage);
8
10
  void onCancel();
9
11
  void onSave();
12
+ void onLog(WritableMap log);
13
+ void onStatistics(WritableMap statistics);
10
14
  }
@@ -7,6 +7,8 @@ import android.net.Uri;
7
7
  import com.arthenica.ffmpegkit.FFmpegKit;
8
8
  import com.arthenica.ffmpegkit.ReturnCode;
9
9
  import com.arthenica.ffmpegkit.SessionState;
10
+ import com.facebook.react.bridge.Arguments;
11
+ import com.facebook.react.bridge.WritableMap;
10
12
  import com.videotrim.interfaces.VideoTrimListener;
11
13
 
12
14
  import java.text.SimpleDateFormat;
@@ -48,15 +50,29 @@ public class VideoTrimmerUtil {
48
50
  // Format the current date and time
49
51
  String formattedDateTime = dateFormat.format(currentDate);
50
52
 
51
- String cmd = "-ss " + startMs + "ms" + " -to " + endMs + "ms -i " + inputFile + " -c copy -metadata creation_time=" + formattedDateTime + " " + outputFile;
52
53
  callback.onStartTrim();
53
- FFmpegKit.executeAsync(cmd, session -> {
54
+
55
+ String[] cmds = {
56
+ "-ss",
57
+ startMs + "ms",
58
+ "-to",
59
+ endMs + "ms",
60
+ "-i",
61
+ inputFile,
62
+ "-c",
63
+ "copy",
64
+ "-metadata",
65
+ "creation_time=" + formattedDateTime,
66
+ outputFile
67
+ };
68
+
69
+ FFmpegKit.executeWithArgumentsAsync(cmds, session -> {
54
70
  SessionState state = session.getState();
55
71
  ReturnCode returnCode = session.getReturnCode();
56
72
 
57
73
  if (ReturnCode.isSuccess(returnCode)) {
58
74
  // SUCCESS
59
- callback.onFinishTrim(outputFile);
75
+ callback.onFinishTrim(outputFile, startMs, endMs, videoDuration);
60
76
  }
61
77
  else {
62
78
  // CANCEL + FAILURE
@@ -64,7 +80,14 @@ public class VideoTrimmerUtil {
64
80
  callback.onError(errorMessage);
65
81
  }
66
82
  }, log -> {
83
+ System.out.println("FFmpeg process started with log " + log.getMessage());
67
84
 
85
+ WritableMap map = Arguments.createMap();
86
+ map.putInt("level", log.getLevel().getValue());
87
+ map.putString("message", log.getMessage());
88
+ map.putDouble("sessionId", log.getSessionId());
89
+ map.putString("logStr", log.toString());
90
+ callback.onLog(map);
68
91
  }, statistics -> {
69
92
  int timeInMilliseconds = (int) statistics.getTime();
70
93
  if (timeInMilliseconds > 0) {
@@ -72,6 +95,18 @@ public class VideoTrimmerUtil {
72
95
  (timeInMilliseconds * 100) / videoDuration;
73
96
  callback.onTrimmingProgress(Math.min(Math.max(completePercentage, 0), 100));
74
97
  }
98
+
99
+ WritableMap map = Arguments.createMap();
100
+ map.putDouble("sessionId", statistics.getSessionId());
101
+ map.putInt("videoFrameNumber", statistics.getVideoFrameNumber());
102
+ map.putDouble("videoFps", statistics.getVideoFps());
103
+ map.putDouble("videoQuality", statistics.getVideoQuality());
104
+ map.putDouble("size", statistics.getSize());
105
+ map.putDouble("time", statistics.getTime());
106
+ map.putDouble("bitrate", statistics.getBitrate());
107
+ map.putDouble("speed", statistics.getSpeed());
108
+ map.putString("statisticsStr", statistics.toString());
109
+ callback.onStatistics(map);
75
110
  });
76
111
  }
77
112