react-native-video-trim 2.2.2 → 2.2.4

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.
@@ -260,14 +260,6 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
260
260
  sendEvent(getReactApplicationContext(), "onLoad", map);
261
261
  }
262
262
 
263
- @Override
264
- public void onStartTrim() {
265
- sendEvent(getReactApplicationContext(), "onStartTrimming", null);
266
- runOnUiThread(() -> {
267
- buildDialog();
268
- });
269
- }
270
-
271
263
  @Override
272
264
  public void onTrimmingProgress(int percentage) {
273
265
  // prevent onTrimmingProgress is called after onFinishTrim (some rare cases)
@@ -361,7 +353,7 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
361
353
  @Override
362
354
  public void onSave() {
363
355
  if (!enableSaveDialog) {
364
- trimmerView.onSaveClicked();
356
+ startTrim();
365
357
  return;
366
358
  }
367
359
 
@@ -371,7 +363,7 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
371
363
  builder.setCancelable(false);
372
364
  builder.setPositiveButton(saveDialogConfirmText, (dialog, which) -> {
373
365
  dialog.cancel();
374
- trimmerView.onSaveClicked();
366
+ startTrim();
375
367
  });
376
368
  builder.setNegativeButton(saveDialogCancelText, (dialog, which) -> {
377
369
  dialog.cancel();
@@ -390,32 +382,7 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
390
382
  sendEvent(getReactApplicationContext(), "onStatistics", statistics);
391
383
  }
392
384
 
393
- private void hideDialog(boolean shouldCloseEditor) {
394
- // handle the case when the cancel dialog is still showing but the trimming is finished
395
- if (cancelTrimmingConfirmDialog != null) {
396
- if (cancelTrimmingConfirmDialog.isShowing()) {
397
- cancelTrimmingConfirmDialog.dismiss();
398
- }
399
- cancelTrimmingConfirmDialog = null;
400
- }
401
-
402
- if (mProgressDialog != null) {
403
- if (mProgressDialog.isShowing()) mProgressDialog.dismiss();
404
- mProgressBar = null;
405
- mProgressDialog = null;
406
- }
407
-
408
- if (shouldCloseEditor) {
409
- if (alertDialog != null) {
410
- if (alertDialog.isShowing()) {
411
- alertDialog.dismiss();
412
- }
413
- alertDialog = null;
414
- }
415
- }
416
- }
417
-
418
- private void buildDialog() {
385
+ private void startTrim() {
419
386
  Activity activity = getReactApplicationContext().getCurrentActivity();
420
387
  // Create the parent layout for the dialog
421
388
  LinearLayout layout = new LinearLayout(activity);
@@ -469,10 +436,7 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
469
436
  builder.setTitle(cancelTrimmingDialogTitle);
470
437
  builder.setCancelable(false);
471
438
  builder.setPositiveButton(cancelTrimmingDialogConfirmText, (dialog, which) -> {
472
- if (trimmerView != null) {
473
- // prevent trimmerView is null in some rare cases
474
- trimmerView.onCancelTrimClicked();
475
- }
439
+ trimmerView.onCancelTrimClicked();
476
440
 
477
441
  if (mProgressDialog != null && mProgressDialog.isShowing()) {
478
442
  mProgressDialog.dismiss();
@@ -484,10 +448,7 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
484
448
  cancelTrimmingConfirmDialog = builder.create();
485
449
  cancelTrimmingConfirmDialog.show();
486
450
  } else {
487
- if (trimmerView != null) {
488
- // prevent trimmerView is null in some rare cases
489
- trimmerView.onCancelTrimClicked();
490
- }
451
+ trimmerView.onCancelTrimClicked();
491
452
 
492
453
  if (mProgressDialog != null && mProgressDialog.isShowing()) {
493
454
  mProgressDialog.dismiss();
@@ -504,9 +465,40 @@ public class VideoTrimModule extends ReactContextBaseJavaModule implements Video
504
465
 
505
466
  // Show the dialog
506
467
  mProgressDialog = builder.create();
468
+
469
+ mProgressDialog.setOnShowListener(dialog -> {
470
+ sendEvent(getReactApplicationContext(), "onStartTrimming", null);
471
+ trimmerView.onSaveClicked();
472
+ });
473
+
507
474
  mProgressDialog.show();
508
475
  }
509
476
 
477
+ private void hideDialog(boolean shouldCloseEditor) {
478
+ // handle the case when the cancel dialog is still showing but the trimming is finished
479
+ if (cancelTrimmingConfirmDialog != null) {
480
+ if (cancelTrimmingConfirmDialog.isShowing()) {
481
+ cancelTrimmingConfirmDialog.dismiss();
482
+ }
483
+ cancelTrimmingConfirmDialog = null;
484
+ }
485
+
486
+ if (mProgressDialog != null) {
487
+ if (mProgressDialog.isShowing()) mProgressDialog.dismiss();
488
+ mProgressBar = null;
489
+ mProgressDialog = null;
490
+ }
491
+
492
+ if (shouldCloseEditor) {
493
+ if (alertDialog != null) {
494
+ if (alertDialog.isShowing()) {
495
+ alertDialog.dismiss();
496
+ }
497
+ alertDialog = null;
498
+ }
499
+ }
500
+ }
501
+
510
502
  @ReactMethod
511
503
  public void addListener(String eventName) {
512
504
  // This method is required by React
@@ -5,7 +5,6 @@ import com.videotrim.enums.ErrorCode;
5
5
 
6
6
  public interface VideoTrimListener {
7
7
  void onLoad(int duration);
8
- void onStartTrim();
9
8
  void onTrimmingProgress(int percentage);
10
9
  void onFinishTrim(String url, long startMs, long endMs, int videoDuration);
11
10
  void onCancelTrim();
@@ -52,8 +52,6 @@ public class VideoTrimmerUtil {
52
52
  // Format the current date and time
53
53
  String formattedDateTime = dateFormat.format(currentDate);
54
54
 
55
- callback.onStartTrim();
56
-
57
55
  String[] cmds = {
58
56
  "-ss",
59
57
  startMs + "ms",
@@ -56,6 +56,9 @@ public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
56
56
 
57
57
  private ReactApplicationContext mContext;
58
58
  private VideoView mVideoView;
59
+ // https://stackoverflow.com/a/73361868/7569705
60
+ // the videoPlayer is to solve the issue after manually seek -> hit play -> it starts from a position slightly before with the one we just sought to
61
+ private MediaPlayer videoPlayer;
59
62
  private ImageView mPlayView;
60
63
  private LinearLayout mThumbnailContainer;
61
64
  private Uri mSourceUri;
@@ -110,6 +113,7 @@ public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
110
113
  private String alertOnFailTitle = "Error";
111
114
  private String alertOnFailMessage = "Fail to load media. Possibly invalid file or no network connection";
112
115
  private String alertOnFailCloseText = "Close";
116
+ private View currentSelectedhandle;
113
117
 
114
118
  public VideoTrimmerView(ReactApplicationContext context, ReadableMap config, AttributeSet attrs) {
115
119
  this(context, attrs, 0, config);
@@ -172,6 +176,7 @@ public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
172
176
  mVideoView.setOnPreparedListener(mp -> {
173
177
  mp.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT);
174
178
  mediaPrepared();
179
+ videoPlayer = mp;
175
180
  });
176
181
 
177
182
  mVideoView.setOnErrorListener(this::onFailToLoadMedia);
@@ -403,7 +408,11 @@ public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
403
408
 
404
409
  private void seekTo(long msec, boolean needUpdateProgress) {
405
410
  if (isVideoType) {
406
- mVideoView.seekTo((int) msec);
411
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
412
+ videoPlayer.seekTo((int) msec, MediaPlayer.SEEK_CLOSEST);
413
+ } else {
414
+ mVideoView.seekTo((int) msec);
415
+ }
407
416
  } else {
408
417
  audioPlayer.seekTo((int) msec);
409
418
  }
@@ -568,6 +577,8 @@ public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
568
577
  currentPosition = duration;
569
578
  } else if (currentPosition >= endTime - 100) {
570
579
  currentPosition = (int) endTime;
580
+ } else if (currentPosition <= startTime + 100) {
581
+ currentPosition = (int) startTime;
571
582
  }
572
583
 
573
584
  String currentTime = formatTime(currentPosition);
@@ -583,9 +594,13 @@ public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
583
594
  // Update progressIndicator position
584
595
  float indicatorPosition = (float) currentPosition / duration * (trimmerContainerBg.getWidth() - progressIndicator.getWidth()) + leadingHandle.getWidth();
585
596
 
586
- float rightBoundary = trimmerContainer.getX() + trimmerContainer.getWidth() - progressIndicator.getWidth();
587
-
588
- progressIndicator.setX(Math.min(rightBoundary, indicatorPosition));
597
+ if (currentSelectedhandle == leadingHandle) {
598
+ float leftBoundary = trimmerContainer.getX();
599
+ progressIndicator.setX(Math.max(leftBoundary, indicatorPosition));
600
+ } else {
601
+ float rightBoundary = trimmerContainer.getX() + trimmerContainer.getWidth() - progressIndicator.getWidth();
602
+ progressIndicator.setX(Math.min(rightBoundary, indicatorPosition));
603
+ }
589
604
  }
590
605
  }
591
606
 
@@ -655,6 +670,7 @@ public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
655
670
  handle.setOnTouchListener((view, event) -> {
656
671
  switch (event.getAction()) {
657
672
  case MotionEvent.ACTION_DOWN:
673
+ currentSelectedhandle = handle;
658
674
  didClampWhilePanning = false;
659
675
  onMediaPause();
660
676
  fadeOutProgressIndicator();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-video-trim",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
4
4
  "description": "Video trimmer for your React Native app",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",