react-native-video-trim 1.0.12 → 1.0.13
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.
- package/README.md +1 -0
- package/android/src/main/java/com/videotrim/VideoTrimModule.java +2 -2
- package/android/src/main/java/com/videotrim/interfaces/VideoTrimListener.java +1 -1
- package/android/src/main/java/com/videotrim/utils/StorageUtil.java +0 -1
- package/android/src/main/java/com/videotrim/utils/VideoTrimmerUtil.java +9 -11
- package/android/src/main/java/com/videotrim/widgets/VideoTrimmerView.java +1 -1
- package/ios/VideoTrim.swift +4 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -181,9 +181,9 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
|
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
@Override public void onError() {
|
|
184
|
+
@Override public void onError(String errorMessage) {
|
|
185
185
|
WritableMap map = Arguments.createMap();
|
|
186
|
-
map.putString("message",
|
|
186
|
+
map.putString("message", errorMessage);
|
|
187
187
|
sendEvent(getReactApplicationContext(), "onError", map);
|
|
188
188
|
this.hideDialog();
|
|
189
189
|
}
|
|
@@ -18,7 +18,6 @@ import java.io.OutputStream;
|
|
|
18
18
|
import java.util.ArrayList;
|
|
19
19
|
import java.util.List;
|
|
20
20
|
|
|
21
|
-
@SuppressWarnings({ "ResultOfMethodCallIgnored", "FieldCanBeLocal" })
|
|
22
21
|
public class StorageUtil {
|
|
23
22
|
public static String getOutputPath(Context context) { // use same extension as inputFile
|
|
24
23
|
long timestamp = System.currentTimeMillis() / 1000;
|
|
@@ -4,17 +4,10 @@ import android.content.Context;
|
|
|
4
4
|
import android.graphics.Bitmap;
|
|
5
5
|
import android.media.MediaMetadataRetriever;
|
|
6
6
|
import android.net.Uri;
|
|
7
|
-
import android.util.Log;
|
|
8
|
-
|
|
9
7
|
import com.arthenica.ffmpegkit.FFmpegKit;
|
|
10
8
|
import com.arthenica.ffmpegkit.ReturnCode;
|
|
11
9
|
import com.arthenica.ffmpegkit.SessionState;
|
|
12
10
|
import com.videotrim.interfaces.VideoTrimListener;
|
|
13
|
-
|
|
14
|
-
import java.text.SimpleDateFormat;
|
|
15
|
-
import java.util.Date;
|
|
16
|
-
import java.util.Locale;
|
|
17
|
-
|
|
18
11
|
import iknow.android.utils.DeviceUtil;
|
|
19
12
|
import iknow.android.utils.UnitConverter;
|
|
20
13
|
import iknow.android.utils.callback.SingleCallback;
|
|
@@ -37,16 +30,21 @@ public class VideoTrimmerUtil {
|
|
|
37
30
|
public static final int THUMB_HEIGHT = UnitConverter.dpToPx(50); // x2 for better resolution
|
|
38
31
|
private static final int THUMB_RESOLUTION_RES = 2; // double thumb resolution for better quality
|
|
39
32
|
|
|
40
|
-
public static void trim(
|
|
33
|
+
public static void trim(String inputFile, String outputFile, int videoDuration, long startMs, long endMs, final VideoTrimListener callback) {
|
|
41
34
|
String cmd = "-i " + inputFile + " -ss " + startMs + "ms" + " -to " + endMs + "ms -c copy " + outputFile;
|
|
42
35
|
callback.onStartTrim();
|
|
43
36
|
FFmpegKit.executeAsync(cmd, session -> {
|
|
44
37
|
SessionState state = session.getState();
|
|
38
|
+
ReturnCode returnCode = session.getReturnCode();
|
|
45
39
|
|
|
46
|
-
if (
|
|
40
|
+
if (ReturnCode.isSuccess(returnCode)) {
|
|
41
|
+
// SUCCESS
|
|
47
42
|
callback.onFinishTrim(outputFile);
|
|
48
|
-
}
|
|
49
|
-
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// CANCEL + FAILURE
|
|
46
|
+
String errorMessage = String.format("Command failed with state %s and rc %s.%s", state, returnCode, session.getFailStackTrace());
|
|
47
|
+
callback.onError(errorMessage);
|
|
50
48
|
}
|
|
51
49
|
}, log -> {
|
|
52
50
|
|
|
@@ -271,7 +271,7 @@ public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
|
|
|
271
271
|
Toast.makeText(mContext, "Video shorter than 3s, can't proceed", Toast.LENGTH_SHORT).show();
|
|
272
272
|
} else {
|
|
273
273
|
mVideoView.pause();
|
|
274
|
-
VideoTrimmerUtil.trim(
|
|
274
|
+
VideoTrimmerUtil.trim(
|
|
275
275
|
mSourceUri.getPath(),
|
|
276
276
|
StorageUtil.getOutputPath(mContext),
|
|
277
277
|
mDuration,
|
package/ios/VideoTrim.swift
CHANGED
|
@@ -306,8 +306,9 @@ class VideoTrim: RCTEventEmitter {
|
|
|
306
306
|
let _ = self.deleteFile(url: inputFile) // remove the file we just copied to document directory
|
|
307
307
|
|
|
308
308
|
let state = session?.getState()
|
|
309
|
+
let returnCode = session?.getReturnCode()
|
|
309
310
|
|
|
310
|
-
if
|
|
311
|
+
if ReturnCode.isSuccess(returnCode) {
|
|
311
312
|
let eventPayload: [String: Any] = ["outputPath": outputFile]
|
|
312
313
|
self.emitEventToJS("onFinishTrimming", eventData: eventPayload)
|
|
313
314
|
|
|
@@ -337,7 +338,8 @@ class VideoTrim: RCTEventEmitter {
|
|
|
337
338
|
}
|
|
338
339
|
}
|
|
339
340
|
} else {
|
|
340
|
-
|
|
341
|
+
// CANCEL + FAILURE
|
|
342
|
+
let eventPayload: [String: Any] = ["message": "Command failed with state \(String(describing: FFmpegKitConfig.sessionState(toString: state ?? .failed))) and rc \(String(describing: returnCode)).\(String(describing: session?.getFailStackTrace()))"]
|
|
341
343
|
self.emitEventToJS("onError", eventData: eventPayload)
|
|
342
344
|
}
|
|
343
345
|
|