react-native-image-crop-picker icon indicating copy to clipboard operation
react-native-image-crop-picker copied to clipboard

I can't able to select iCloud synced video or image in iOS

Open NaveenConcertcare opened this issue 4 years ago • 6 comments

Version

Tell us which versions you are using:

  • react-native-image-crop-picker v0.33.1
  • react-native v0.61.4

Platform

Tell us to which platform this issue is related

  • iOS i can't able to select iCloud synced video or image

Expected behaviour

i want to select iCloud image or video

Actual behaviour

if i select icloud video or image it just closing the picker

Steps to reproduce

1.In ios open image picker - openPicker

2.select icloud videos or images

3.You can't select

Attachments

// stacktrace or any other useful debug info

Love react-native-image-crop-picker? Please consider supporting our collective: 👉 https://opencollective.com/react-native-image-crop-picker/donate

NaveenConcertcare avatar Jan 21 '21 12:01 NaveenConcertcare

I have same issue for video. :(

nmhoan76 avatar Feb 17 '21 02:02 nmhoan76

There seems to be a larger discussion related to this here: https://github.com/ivpusic/react-native-image-crop-picker/issues/1415

It looks like an issue with uploading videos from iCloud has been resolved but the issue still exists with images. I am facing the same issues with image uploads on iOS 14.

chrisvasey avatar Feb 28 '21 21:02 chrisvasey

same issue upload video from iCloud , hi @chrisvasey any solution ?

cenaHara avatar Mar 02 '21 10:03 cenaHara

Sadly no, I have not been able to resolve this one. One thing I have found is that after the user clicks the video it downloads so the next time it is selected it will attach.

For now, I have added some error messages in my app but am hopeful for a fix soon from someone who understands the native code.

chrisvasey avatar Mar 02 '21 10:03 chrisvasey

You will check the error message: "Cannot process video data"

cenaHara avatar Mar 02 '21 10:03 cenaHara

I resolved this issue for videos by converting the AVURLAsset to AVMutableComposition. I changed the function compressVideo in Compression.m to:

- (void)compressVideo:(NSURL*)inputURL
            outputURL:(NSURL*)outputURL
          withOptions:(NSDictionary*)options
              handler:(void (^)(AVAssetExportSession*))handler {
    
    NSString *presetKey = [options valueForKey:@"compressVideoPreset"];
    if (presetKey == nil) {
        presetKey = @"MediumQuality";
    }
    
    NSString *preset = [self.exportPresets valueForKey:presetKey];
    if (preset == nil) {
        preset = AVAssetExportPresetMediumQuality;
    }
    
    [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
    AVMutableComposition* mixComposition = [[AVMutableComposition alloc] init];
    if (asset != NULL) {
        //VIDEO TRACK
        // Grab the source track from AVURLAsset for example.
        AVAssetTrack *assetVideoTrack = [asset tracksWithMediaType:AVMediaTypeVideo].lastObject;
        
        // Grab the composition video track from AVMutableComposition you already made.
        AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
        
        [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration) ofTrack:[[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil];
        
        // Apply the original transform.
        if (assetVideoTrack && compositionVideoTrack) {
            [compositionVideoTrack setPreferredTransform:assetVideoTrack.preferredTransform];
        }
        
        //AUDIO TRACK
        AVMutableVideoCompositionInstruction * MainInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
        MainInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, asset.duration);
        
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
        [audioSession setActive:YES error:nil];
        
        AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
        
        [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration) ofTrack:[[asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil];
    }
           
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:preset];
    exportSession.shouldOptimizeForNetworkUse = YES;
    exportSession.outputURL = outputURL;
    exportSession.outputFileType = AVFileTypeMPEG4;
    
    [exportSession exportAsynchronouslyWithCompletionHandler:^(void) {
        handler(exportSession);
    }];
}

Hope this helps someone.

timok06 avatar Sep 16 '22 10:09 timok06