开发者

MOV playback not working using UIImagePickerController with MPMoviePlayerController

开发者 https://www.devze.com 2023-04-09 04:50 出处:网络
I have read similar threads regarding movie playback in a MPMoviePlayerController after selecting a video using UIImagePickerController including:

I have read similar threads regarding movie playback in a MPMoviePlayerController after selecting a video using UIImagePickerController including:

MPMoviePlayerController do not play movie picked from UIImagePickerController

  • Releasing the picker and/or the movieP开发者_开发问答layer on playback complete or a combination of the two does not resolve my issue.

Problem playing mov file in MPMoviePlayerController

  • My movie is recorded via the iPhone real-time and will not have any codec issues - its a standard MOV

My code is below - and believe me, I have tried every permutation I can fathom with this code. I have also tried to use MPMoviePlayerViewController, presenting it modally using the UIViewController MediaPlayer Additions - presentMoviePlayerViewControllerAnimated

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [self.navigationController dismissModalViewControllerAnimated:YES];

    if ( currentMediaType == kMediaTypeVideo ) {
        MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[info objectForKey:@"UIImagePickerControllerMediaURL"]];
        moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
        [moviePlayer.view setFrame:current_player_view.bounds];
        [current_player_view addSubview:moviePlayer.view];
    }

}

I have also tried adjusting how I provide the movie path to the MPMoviePlayerController - I recognize I can access the path like so:

[[info objectForKey:@"UIImagePickerControllerMediaURL"] path];

...and therefore can provide the NSURL with this code instead:

NSString *chosenMoviePath = [[info objectForKey:@"UIImagePickerControllerMediaURL"] path];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:chosenMoviePath]];

However this does not resolve the issue either. There really shouldn't be any crazy extreme trick to recording a video and immediately playing said video in the movie player. Seriously. Its all on the device. Any help is extremely appreciated. I've spent much to much time on this already.

Thanks in advance!

J


To resolve - I finally discovered if I don't animate the dismissModalViewController for the UIImagePickerController, then the playback displays for the video. The best I can conclude is that the animated dismissal has a delay which can cause other code to not execute immediately. So below works:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [self.navigationController dismissModalViewControllerAnimated:NO];

    if ( currentMediaType == kMediaTypeVideo ) {
        MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[info objectForKey:@"UIImagePickerControllerMediaURL"]];
        moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
        [moviePlayer.view setFrame:current_player_view.bounds];
        [current_player_view addSubview:moviePlayer.view];
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号