1
votes

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?

2

2 Answers

3
votes

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.

1
votes

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.