react-native-video-trim 6.0.7 → 6.0.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.
@@ -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(outputFile)
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) -> {
@@ -527,14 +527,90 @@ public class VideoTrim: RCTEventEmitter, AssetLoaderDelegate, UIDocumentPickerDe
527
527
  let returnCode = session?.getReturnCode()
528
528
 
529
529
  if ReturnCode.isSuccess(returnCode) {
530
- let result = [
531
- "success": true,
532
- "outputPath": outputFile.absoluteString,
533
- "startTime": startTime,
534
- "endTime": endTime
535
- ] as [String : Any]
536
-
537
- completion(result)
530
+ // Handle saveToPhoto functionality
531
+ if let saveToPhoto = config["saveToPhoto"] as? Bool, saveToPhoto {
532
+ print("iOS trim: saveToPhoto is true, attempting to save to photo library")
533
+ // Check if it's a video type
534
+ let isVideoType = (config["type"] as? String ?? "video") == "video"
535
+
536
+ if isVideoType {
537
+ PHPhotoLibrary.requestAuthorization { status in
538
+ DispatchQueue.main.async {
539
+ if status == .authorized {
540
+ PHPhotoLibrary.shared().performChanges({
541
+ PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: outputFile)
542
+ }) { success, error in
543
+ if success {
544
+ print("Edited video saved to Photo Library successfully.")
545
+
546
+ // Handle removeAfterSavedToPhoto
547
+ if let removeAfterSaved = config["removeAfterSavedToPhoto"] as? Bool, removeAfterSaved {
548
+ let _ = VideoTrim.deleteFile(url: outputFile.absoluteString)
549
+ }
550
+
551
+ let result = [
552
+ "outputPath": outputFile.absoluteString,
553
+ "startTime": startTime,
554
+ "endTime": endTime,
555
+ "duration": endTime - startTime
556
+ ] as [String : Any]
557
+
558
+ completion(result)
559
+ } else {
560
+ print("Failed to save edited video to Photo Library: \(error?.localizedDescription ?? "Unknown error")")
561
+
562
+ // Handle removeAfterFailedToSavePhoto
563
+ if let removeAfterFailed = config["removeAfterFailedToSavePhoto"] as? Bool, removeAfterFailed {
564
+ let _ = VideoTrim.deleteFile(url: outputFile.absoluteString)
565
+ }
566
+
567
+ let result = [
568
+ "success": false,
569
+ "message": "Failed to save edited video to Photo Library: \(error?.localizedDescription ?? "Unknown error")",
570
+ ] as [String : Any]
571
+
572
+ completion(result)
573
+ }
574
+ }
575
+ } else {
576
+ // Permission denied
577
+ print("Photo Library access denied")
578
+
579
+ // Handle removeAfterFailedToSavePhoto
580
+ if let removeAfterFailed = config["removeAfterFailedToSavePhoto"] as? Bool, removeAfterFailed {
581
+ let _ = VideoTrim.deleteFile(url: outputFile.absoluteString)
582
+ }
583
+
584
+ let result = [
585
+ "success": false,
586
+ "message": "Photo Library access denied",
587
+ ] as [String : Any]
588
+
589
+ completion(result)
590
+ }
591
+ }
592
+ }
593
+ } else {
594
+ // For audio files, we can't save to photo library, just return success
595
+ let result = [
596
+ "outputPath": outputFile.absoluteString,
597
+ "startTime": startTime,
598
+ "endTime": endTime,
599
+ "duration": endTime - startTime
600
+ ] as [String : Any]
601
+
602
+ completion(result)
603
+ }
604
+ } else {
605
+ let result = [
606
+ "outputPath": outputFile.absoluteString,
607
+ "startTime": startTime,
608
+ "endTime": endTime,
609
+ "duration": endTime - startTime
610
+ ] as [String : Any]
611
+
612
+ completion(result)
613
+ }
538
614
  } else if ReturnCode.isCancel(returnCode) {
539
615
  // CANCEL
540
616
  let result = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-video-trim",
3
- "version": "6.0.7",
3
+ "version": "6.0.8",
4
4
  "description": "Video trimmer for your React Native app",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",