我在这个问题上运行了几天。我需要从相机胶卷中选择一个视频并直接在我的应用中播放。我想知道的只是:它有可能吗?因为我的代码在我从相机胶卷中挑选后没有播放视频,我怀疑在播放之前我可能需要将视频保存在本地。
我的相关代码如下:
//...
if (CFStringCompare((CFStringRef)mediaType, kUTTypeMovie, 0)==kCFCompareEqualTo) {
NSString *moviePath=[[info objectForKey:UIImagePickerControllerMediaURL]path];
NSURL *movieURL=[NSURL URLWithString:moviePath];
self.mpController=[[MPMoviePlayerController alloc]initWithContentURL:movieURL];
NSLog(@"%@",moviePath);
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.mpController];
self.mpController.movieSourceType=MPMovieSourceTypeStreaming;
self.mpController.controlStyle=MPMediaTypeMusicVideo;
[self.mpController prepareToPlay];
[self.mpController.view setFrame:self.view.bounds];
[self.mpController setFullscreen:YES animated:YES];
[self.view addSubview:self.mpController.view];
[self.mpController play];
}
[[picker presentingViewController] dismissViewControllerAnimated:YES completion:NULL];
//...
-(void)moviePlayBackDidFinish:(NSNotification*)notification{
NSLog(@"moviePlayBAckDidFinish");
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player
respondsToSelector:@selector(setFullscreen:animated:)])
{
player.fullscreen=NO;
[player.view removeFromSuperview];
}
}
P.S :压缩视频后,通知处理程序moviePlayBackDidFinish
总是被调用,我得到一个空白屏幕。此外,记录moviePath
变量给了我这样的路径:
/private/var/mobile/Applications/5912AED1-S1DE-25EF-A8B-EF7AD21E3R65/tmp//trim.uUcGJU.MOV
正如我所说,我认为我怀疑直接从相机胶卷播放视频是不可能的。但我需要你确认一下。感谢名单。