react-native-video-trim 2.2.6 → 2.2.8

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.
@@ -522,8 +522,15 @@ public class VideoTrimmerView extends FrameLayout implements IVideoTrimmerView {
522
522
  @Override
523
523
  public void run() {
524
524
  try {
525
- updateCurrentTime(true);
526
- mTimingHandler.postDelayed(this, TIMING_UPDATE_INTERVAL);
525
+ int currentPosition = mediaPlayer.getCurrentPosition();
526
+
527
+ if (currentPosition >= endTime) {
528
+ onMediaPause();
529
+ seekTo(endTime, true); // Ensure exact end time display
530
+ } else {
531
+ updateCurrentTime(true);
532
+ mTimingHandler.postDelayed(this, TIMING_UPDATE_INTERVAL);
533
+ }
527
534
  } catch (IllegalStateException e) {
528
535
  e.printStackTrace();
529
536
  mTimingHandler.removeCallbacks(mTimingRunnable);
@@ -121,7 +121,9 @@ class VideoTrim: RCTEventEmitter, AssetLoaderDelegate, UIDocumentPickerDelegate
121
121
  }
122
122
 
123
123
  let destPath = URL(string: uri)
124
- guard let destPath = destPath else { return }
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
  }
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ </Workspace>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-video-trim",
3
- "version": "2.2.6",
3
+ "version": "2.2.8",
4
4
  "description": "Video trimmer for your React Native app",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",