Uiimagepickercontroller didfinishpickingmediawithinfo NOT CALLED when selecting video from library

I am writing an application where a user can select photos and videos from a library. I want to implement my own video player when a video is selected, but the application immediately launches the default player which has a select button.

Didfinishpickingmediawithinfo function is not called. This only happens when a video is selected. I can display the selected photo to the screen because the delegate method is called when a photo is selected.

Why isn't the collector's delegate method only called when the video is fetched from the library?

Code for library button:

//Library access function displays photos and videos stored on the device
- (IBAction)selectPhoto:(UIButton *)sender {

UIImagePickerController *picker2 = [[UIImagePickerController alloc] init];
picker2.delegate = self;
picker2.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker2.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:picker2.sourceType];
picker2.allowsEditing = NO;

self.picker2 = picker2;

[self.picker dismissViewControllerAnimated:YES completion:^{
    [self presentViewController:self.picker2 animated:YES completion:NULL];}];
}

      

I am including delegates in a view controller. A lot of the questions I've researched indicate a lack of inclusion in the header of the view controller, but I assure you they are there.

Here is the code to enable:

@interface ViewController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIGestureRecognizerDelegate>

      

I have placed NSLog statements in the delegate method and I can see that they are executed in all other cases when using the collector. However, if you select video, the NSLog instructions are not displayed.

If anyone has had this problem before and came up with a solution, please share it. I've searched for many days and haven't found a solution to this problem.

The person in this thread had a problem, but the problem was not resolved.

All this question can suggest as a solution that I have implemented in my program.

I have added the following code as requested.

Delegate method:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    NSLog(@"didfinishpicking method triggered");
    // Get the type of media selected
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];

    // Handling Media Capturing (Images/Videos)
    // When an image is taken
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage] && picker.sourceType == UIImagePickerControllerSourceTypeCamera) {

        // Save the taken photo to the camera roll library
        UIImage *imageTaken = [info valueForKey:UIImagePickerControllerOriginalImage];
        UIImageWriteToSavedPhotosAlbum(imageTaken, nil, nil, nil);

        // Update the library button image
        [self.imageButton setImage:imageTaken forState:UIControlStateNormal];

    }

    // When a video is taken
    else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie] && picker.sourceType == UIImagePickerControllerSourceTypeCamera) {

        // Grab the URL for the video just taken
        NSURL *newVideo = [info objectForKey:UIImagePickerControllerMediaURL];

        // Save the video to the camera roll
        UISaveVideoAtPathToSavedPhotosAlbum([newVideo path], nil, nil, nil);


    }

    // Handling Library Previewing
    // When an image is selected
    else if ([mediaType isEqualToString:(NSString *)kUTTypeImage] && picker.sourceType != UIImagePickerControllerSourceTypeCamera) {

        NSLog(@"A picture was selected from the library.");

        UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
        self.libraryImage.image = image;

        self.libraryView.translatesAutoresizingMaskIntoConstraints = YES;

        [[UIApplication sharedApplication].keyWindow addSubview: self.libraryView];

    }

    // When a video is selected
    else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie] && picker.sourceType != UIImagePickerControllerSourceTypeCamera) {
        NSLog(@"A video was selected from the library.");
    }
}

      

Even with a time delay as the suggested picker2 is still broken. I used the following answer to delay the call.

This was the result when I first tried to select a video and then select a photo. This was done with dismissal, then a delay before introducing a second collector.

> 2014-12-30 00:11:57.763 Sneak[228:907] [MPAVController] Autoplay:
> Enabling autoplay 2014-12-30 00:11:57.766 Sneak[228:907]
> [MPAVController] Autoplay: Skipping autoplay, disabled (for current
> item: 0, on player: 1) 2014-12-30 00:11:57.853 Sneak[228:907]
> [MPAVController] Autoplay: Enabling autoplay 2014-12-30 00:11:58.052
> Sneak[228:907] [MPCloudAssetDownloadController] Prioritization
> requested for media item ID: 0 2014-12-30 00:11:58.897 Sneak[228:907]
> [MPAVController] Autoplay: Skipping autoplay, disabled (for current
> item: 0, on player: 1) 2014-12-30 00:11:58.911 Sneak[228:907]
> [MPAVController] Autoplay: _streamLikelyToKeepUp: 0 -> 1 2014-12-30
> 00:12:17.576 Sneak[228:907] didfinishpicking method triggered
> 2014-12-30 00:12:17.579 Sneak[228:907] A picture was selected from the
> library.

      

I did more testing and found that the delegate method is called when a video is selected, but only when the select button is pressed on the default video player display.

I still don't know how to get the delegate method to be called directly when selecting a video from the library and bypass the default video player. Does this additional information provide any other ideas?

+3


source to share


1 answer


Before the picker2 view, set the property picker2.allowsEditing=NO



Let me know if this works for you or not.

-1


source







All Articles