在使用UIImagePickerController选择视频后,我已经阅读了有关MPMoviePlayerController中电影播放的类似线程,包括:
MPMoviePlayerController do not play movie picked from UIImagePickerController
Problem playing mov file in MPMoviePlayerController
我的代码在下面 - 并且相信我,我已经尝试了我能用这段代码理解的每一个排列。我也尝试使用MPMoviePlayerViewController,使用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];
}
}
我也尝试调整我如何提供MPMoviePlayerController的电影路径 - 我知道我可以像这样访问路径:
[[info objectForKey:@"UIImagePickerControllerMediaURL"] path];
...因此可以为NSURL提供此代码:
NSString *chosenMoviePath = [[info objectForKey:@"UIImagePickerControllerMediaURL"] path];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:chosenMoviePath]];
然而,这也无法解决问题。真的不应该有任何疯狂的极端技巧来录制视频并立即在电影播放器中播放所述视频。认真。它全部在设备上。任何帮助非常赞赏。我已经花了很多时间在这上面。
提前致谢!
Ĵ
答案 0 :(得分:4)
要解决 - 我终于发现如果我没有为UIImagePickerController设置dismissModalViewController的动画,则会显示视频的回放。我能得出的最好结论是,动画解雇有一个延迟,可能导致其他代码不能立即执行。以下是有效的:
- (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];
}
}