react-native-video-trim 2.2.3 → 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.
@@ -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.3",
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",