react-native-video-trim 6.0.7 → 6.0.9
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.
|
@@ -609,19 +609,32 @@ open class BaseVideoTrimModule internal constructor(
|
|
|
609
609
|
when {
|
|
610
610
|
ReturnCode.isSuccess(returnCode) -> {
|
|
611
611
|
// SUCCESS
|
|
612
|
+
val startTime = options?.getDouble("startTime") ?: 0.0
|
|
613
|
+
val endTime = options?.getDouble("endTime") ?: 1000.0
|
|
614
|
+
val duration = endTime - startTime
|
|
615
|
+
|
|
616
|
+
val result = Arguments.createMap()
|
|
617
|
+
result.putString("outputPath", outputFile)
|
|
618
|
+
result.putDouble("startTime", startTime)
|
|
619
|
+
result.putDouble("endTime", endTime)
|
|
620
|
+
result.putDouble("duration", duration)
|
|
621
|
+
|
|
612
622
|
if (options?.getBoolean("saveToPhoto") == true && options.getString("type") == "video") {
|
|
623
|
+
Log.d(TAG, "Android trim: saveToPhoto is true, attempting to save to gallery")
|
|
613
624
|
try {
|
|
614
625
|
StorageUtil.saveVideoToGallery(reactApplicationContext, outputFile)
|
|
615
626
|
Log.d(TAG, "Edited video saved to Photo Library successfully.")
|
|
616
627
|
if (options.getBoolean("removeAfterSavedToPhoto")) {
|
|
628
|
+
Log.d(TAG, "Removing file after successful save to photo")
|
|
617
629
|
StorageUtil.deleteFile(outputFile)
|
|
618
630
|
}
|
|
619
631
|
|
|
620
|
-
promise.resolve(
|
|
632
|
+
promise.resolve(result)
|
|
621
633
|
} catch (e: IOException) {
|
|
622
634
|
e.printStackTrace()
|
|
623
635
|
|
|
624
636
|
if (options.getBoolean("removeAfterFailedToSavePhoto")) {
|
|
637
|
+
Log.d(TAG, "Removing file after failed save to photo")
|
|
625
638
|
StorageUtil.deleteFile(outputFile)
|
|
626
639
|
}
|
|
627
640
|
|
|
@@ -629,6 +642,10 @@ open class BaseVideoTrimModule internal constructor(
|
|
|
629
642
|
Exception("Failed to save edited video to Photo Library: " + e.localizedMessage)
|
|
630
643
|
)
|
|
631
644
|
}
|
|
645
|
+
} else {
|
|
646
|
+
Log.d(TAG, "Android trim: saveToPhoto is false or not video type, resolving with structured result")
|
|
647
|
+
|
|
648
|
+
promise.resolve(result)
|
|
632
649
|
}
|
|
633
650
|
}
|
|
634
651
|
ReturnCode.isCancel(returnCode) -> {
|
package/ios/VideoTrim.swift
CHANGED
|
@@ -211,8 +211,6 @@ public class VideoTrim: RCTEventEmitter, AssetLoaderDelegate, UIDocumentPickerDe
|
|
|
211
211
|
|
|
212
212
|
@objc public weak var delegate: VideoTrimProtocol?
|
|
213
213
|
@objc public var isNewArch = false
|
|
214
|
-
|
|
215
|
-
|
|
216
214
|
|
|
217
215
|
// MARK: for old arch
|
|
218
216
|
private var hasListeners = false
|
|
@@ -527,14 +525,90 @@ public class VideoTrim: RCTEventEmitter, AssetLoaderDelegate, UIDocumentPickerDe
|
|
|
527
525
|
let returnCode = session?.getReturnCode()
|
|
528
526
|
|
|
529
527
|
if ReturnCode.isSuccess(returnCode) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
"
|
|
533
|
-
|
|
534
|
-
"
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
528
|
+
// Handle saveToPhoto functionality
|
|
529
|
+
if let saveToPhoto = config["saveToPhoto"] as? Bool, saveToPhoto {
|
|
530
|
+
print("iOS trim: saveToPhoto is true, attempting to save to photo library")
|
|
531
|
+
// Check if it's a video type
|
|
532
|
+
let isVideoType = (config["type"] as? String ?? "video") == "video"
|
|
533
|
+
|
|
534
|
+
if isVideoType {
|
|
535
|
+
PHPhotoLibrary.requestAuthorization { status in
|
|
536
|
+
DispatchQueue.main.async {
|
|
537
|
+
if status == .authorized {
|
|
538
|
+
PHPhotoLibrary.shared().performChanges({
|
|
539
|
+
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: outputFile)
|
|
540
|
+
}) { success, error in
|
|
541
|
+
if success {
|
|
542
|
+
print("Edited video saved to Photo Library successfully.")
|
|
543
|
+
|
|
544
|
+
// Handle removeAfterSavedToPhoto
|
|
545
|
+
if let removeAfterSaved = config["removeAfterSavedToPhoto"] as? Bool, removeAfterSaved {
|
|
546
|
+
let _ = VideoTrim.deleteFile(url: outputFile)
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
let result = [
|
|
550
|
+
"outputPath": outputFile.absoluteString,
|
|
551
|
+
"startTime": startTime,
|
|
552
|
+
"endTime": endTime,
|
|
553
|
+
"duration": endTime - startTime
|
|
554
|
+
] as [String : Any]
|
|
555
|
+
|
|
556
|
+
completion(result)
|
|
557
|
+
} else {
|
|
558
|
+
print("Failed to save edited video to Photo Library: \(error?.localizedDescription ?? "Unknown error")")
|
|
559
|
+
|
|
560
|
+
// Handle removeAfterFailedToSavePhoto
|
|
561
|
+
if let removeAfterFailed = config["removeAfterFailedToSavePhoto"] as? Bool, removeAfterFailed {
|
|
562
|
+
let _ = VideoTrim.deleteFile(url: outputFile)
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
let result = [
|
|
566
|
+
"success": false,
|
|
567
|
+
"message": "Failed to save edited video to Photo Library: \(error?.localizedDescription ?? "Unknown error")",
|
|
568
|
+
] as [String : Any]
|
|
569
|
+
|
|
570
|
+
completion(result)
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
} else {
|
|
574
|
+
// Permission denied
|
|
575
|
+
print("Photo Library access denied")
|
|
576
|
+
|
|
577
|
+
// Handle removeAfterFailedToSavePhoto
|
|
578
|
+
if let removeAfterFailed = config["removeAfterFailedToSavePhoto"] as? Bool, removeAfterFailed {
|
|
579
|
+
let _ = VideoTrim.deleteFile(url: outputFile)
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
let result = [
|
|
583
|
+
"success": false,
|
|
584
|
+
"message": "Photo Library access denied",
|
|
585
|
+
] as [String : Any]
|
|
586
|
+
|
|
587
|
+
completion(result)
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
} else {
|
|
592
|
+
// For audio files, we can't save to photo library, just return success
|
|
593
|
+
let result = [
|
|
594
|
+
"outputPath": outputFile.absoluteString,
|
|
595
|
+
"startTime": startTime,
|
|
596
|
+
"endTime": endTime,
|
|
597
|
+
"duration": endTime - startTime
|
|
598
|
+
] as [String : Any]
|
|
599
|
+
|
|
600
|
+
completion(result)
|
|
601
|
+
}
|
|
602
|
+
} else {
|
|
603
|
+
let result = [
|
|
604
|
+
"outputPath": outputFile.absoluteString,
|
|
605
|
+
"startTime": startTime,
|
|
606
|
+
"endTime": endTime,
|
|
607
|
+
"duration": endTime - startTime
|
|
608
|
+
] as [String : Any]
|
|
609
|
+
|
|
610
|
+
completion(result)
|
|
611
|
+
}
|
|
538
612
|
} else if ReturnCode.isCancel(returnCode) {
|
|
539
613
|
// CANCEL
|
|
540
614
|
let result = [
|
|
@@ -937,9 +1011,8 @@ extension VideoTrim {
|
|
|
937
1011
|
@objc(isValidFile:withResolver:withRejecter:)
|
|
938
1012
|
func isValidFile(uri: String, resolve: @escaping RCTPromiseResolveBlock,reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
939
1013
|
VideoTrim.isValidFile(url: uri, completion: { payload in
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
)
|
|
1014
|
+
resolve(payload)
|
|
1015
|
+
})
|
|
943
1016
|
}
|
|
944
1017
|
|
|
945
1018
|
private static func checkFileValidity(url: URL, completion: @escaping (Bool, String, Double) -> Void) {
|