react-native-video-trim 2.2.6 → 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.
- package/ios/VideoTrim.swift +38 -2
- package/package.json +1 -1
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
|
}
|