简体   繁体   中英

MPMoviePlayerController do not play movie picked from UIImagePickerController

I have strange MPMoviePlayerController behavior. It don't want to play movies just chosen from UIImagePickerController's Camera Roll. But when I capture movie with UIImagePickerController - sometimes it plays in MPMoviePlayerController fine.

This is UIImagePickerController initialization:

mediaPickerController = [[[UIImagePickerController alloc] init] autorelease];
NSArray *types = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
mediaPickerController.sourceType = sourceType;
mediaPickerController.mediaTypes = types;
mediaPickerController.videoQuality = qualityType;
mediaPickerController.delegate = self;
[self presentModalViewController:mediaPickerController animated:YES];   

This is - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info delegate method:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSURL *fileURL = [info objectForKey:UIImagePickerControllerMediaURL];
    playerView = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
    [playerView.view setFrame:mediaPreview.bounds];
    [playerView setScalingMode:MPMovieScalingModeAspectFit];
    [playerView setControlStyle:MPMovieControlStyleEmbedded];
    [playerView setShouldAutoplay:NO];
    [playerView prepareToPlay];
    [mediaPreview addSubview:playerView.view];
}

Another strange issue - when I use UIImagePickerController's sourceType = Camera, then delegate return next path and plays fine:

UIImagePickerControllerMediaURL = "file://localhost/private/var/mobile/Applications/XXXXX-XXXXX/tmp/capture-T0x127bb0.tmp.5gFkOo/capturedvideo.MOV"

but when sourceType = Library, path looks incorrect and movie appears at half second and disappears:

UIImagePickerControllerMediaURL = "file://localhost/private/var/mobile/Applications/XXXXX-XXXXX/tmp//trim.ZPeyTU.MOV"

Have any ideas?

I had the same thing, occurring only on the iPad 2, while the same exact code worked fine on an iPhone 4.

It turned out that the image picker wasn't being properly released after returning the video.

Try adding [picker release] in the didFinishPickingMediaWithInfo callback.

The issue is pretty non obvious. The older iPhone devices after releasing of media picker tries to delete saved file also. So to use it properly I copy it to Documents folder (for example) before and then set video to movie player. Devices after 4.3 hasn't this problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM