react-native-video-trim 2.2.5 → 2.2.7
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.
|
@@ -327,8 +327,10 @@ public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
|
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
private void mediaCompleted() {
|
|
330
|
-
|
|
331
|
-
|
|
330
|
+
onMediaPause();
|
|
331
|
+
|
|
332
|
+
// when mediaCompleted is called, the endTime may not be exactly at the end of the video (can be slightly before), therefore we should seek to exact position on ended
|
|
333
|
+
seekTo(endTime, true);
|
|
332
334
|
}
|
|
333
335
|
|
|
334
336
|
private void playOrPause() {
|
|
@@ -345,11 +347,9 @@ public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
|
|
|
345
347
|
}
|
|
346
348
|
|
|
347
349
|
public void onMediaPause() {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
setPlayPauseViewIcon(false);
|
|
352
|
-
}
|
|
350
|
+
mTimingHandler.removeCallbacks(mTimingRunnable);
|
|
351
|
+
mediaPlayer.pause();
|
|
352
|
+
setPlayPauseViewIcon(false);
|
|
353
353
|
}
|
|
354
354
|
|
|
355
355
|
public void setOnTrimVideoListener(VideoTrimListener onTrimVideoListener) {
|
|
@@ -521,27 +521,13 @@ public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
|
|
|
521
521
|
mTimingRunnable = new Runnable() {
|
|
522
522
|
@Override
|
|
523
523
|
public void run() {
|
|
524
|
-
// prevent crashing when video is playing and we close editor
|
|
525
524
|
try {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
525
|
+
updateCurrentTime(true);
|
|
526
|
+
mTimingHandler.postDelayed(this, TIMING_UPDATE_INTERVAL);
|
|
530
527
|
} catch (IllegalStateException e) {
|
|
531
528
|
e.printStackTrace();
|
|
532
529
|
mTimingHandler.removeCallbacks(mTimingRunnable);
|
|
533
|
-
|
|
534
|
-
return;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
int currentPosition = mediaPlayer.getCurrentPosition();
|
|
538
|
-
|
|
539
|
-
if (currentPosition >= endTime) {
|
|
540
|
-
onMediaPause();
|
|
541
|
-
seekTo(endTime, true); // Ensure exact end time display
|
|
542
|
-
} else {
|
|
543
|
-
updateCurrentTime(true);
|
|
544
|
-
mTimingHandler.postDelayed(this, TIMING_UPDATE_INTERVAL);
|
|
530
|
+
// this is to catch the error thrown if we close editor while playing (mediaPlayer is released)
|
|
545
531
|
}
|
|
546
532
|
}
|
|
547
533
|
};
|
|
@@ -549,10 +535,7 @@ public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
|
|
|
549
535
|
}
|
|
550
536
|
|
|
551
537
|
private void updateCurrentTime(boolean needUpdateProgress) {
|
|
552
|
-
// TODO: check the case after drag the progress indicator and hit play, it'll play a little bit earlier than the progress indicator
|
|
553
|
-
|
|
554
538
|
int currentPosition = mediaPlayer.getCurrentPosition();
|
|
555
|
-
|
|
556
539
|
int duration = mDuration;
|
|
557
540
|
|
|
558
541
|
if (currentPosition >= duration - 100) {
|
package/ios/VideoTrim.swift
CHANGED
|
@@ -121,7 +121,9 @@ class VideoTrim: RCTEventEmitter, AssetLoaderDelegate, UIDocumentPickerDelegate
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
let destPath = URL(string: uri)
|
|
124
|
-
|
|
124
|
+
let newPath = renameFile(at: destPath!, newName: "beforeTrim")
|
|
125
|
+
|
|
126
|
+
guard let destPath = newPath else { return }
|
|
125
127
|
|
|
126
128
|
DispatchQueue.main.async {
|
|
127
129
|
self.vc = VideoTrimmerViewController()
|
|
@@ -509,7 +511,7 @@ class VideoTrim: RCTEventEmitter, AssetLoaderDelegate, UIDocumentPickerDelegate
|
|
|
509
511
|
|
|
510
512
|
func assetLoader(_ loader: AssetLoader, didFailWithError error: any Error, forKey key: String) {
|
|
511
513
|
let message = "Failed to load \(key): \(error.localizedDescription)"
|
|
512
|
-
print(message)
|
|
514
|
+
print("Failed to load \(key)", message)
|
|
513
515
|
|
|
514
516
|
self.onError(message: message, code: .failToLoadMedia)
|
|
515
517
|
vc?.onAssetFailToLoad()
|
|
@@ -698,4 +700,38 @@ class VideoTrim: RCTEventEmitter, AssetLoaderDelegate, UIDocumentPickerDelegate
|
|
|
698
700
|
}
|
|
699
701
|
}
|
|
700
702
|
}
|
|
703
|
+
|
|
704
|
+
private func renameFile(at url: URL, newName: String) -> URL? {
|
|
705
|
+
let fileManager = FileManager.default
|
|
706
|
+
|
|
707
|
+
// Get the directory of the existing file
|
|
708
|
+
let directory = url.deletingLastPathComponent()
|
|
709
|
+
|
|
710
|
+
// Get the file extension
|
|
711
|
+
let fileExtension = url.pathExtension
|
|
712
|
+
|
|
713
|
+
// Create the new file URL with the new name and the same extension
|
|
714
|
+
let newFileURL = directory.appendingPathComponent(newName).appendingPathExtension(fileExtension)
|
|
715
|
+
|
|
716
|
+
// Check if a file with the new name already exists
|
|
717
|
+
if fileManager.fileExists(atPath: newFileURL.path) {
|
|
718
|
+
do {
|
|
719
|
+
// If the file exists, remove it first to avoid conflicts
|
|
720
|
+
try fileManager.removeItem(at: newFileURL)
|
|
721
|
+
} catch {
|
|
722
|
+
print("Error removing existing file: \(error)")
|
|
723
|
+
return nil
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
do {
|
|
728
|
+
// Rename (move) the file
|
|
729
|
+
try fileManager.moveItem(at: url, to: newFileURL)
|
|
730
|
+
print("File renamed successfully to \(newFileURL.absoluteString)")
|
|
731
|
+
return newFileURL
|
|
732
|
+
} catch {
|
|
733
|
+
print("Error renaming file: \(error)")
|
|
734
|
+
return nil
|
|
735
|
+
}
|
|
736
|
+
}
|
|
701
737
|
}
|