1

我在这个问题上运行了几天。我需要从我的相机胶卷中挑选一个视频并直接在我的应用程序中播放。我想知道的很简单:这可能吗?因为我下面的代码在我从相机胶卷中挑选视频后不会播放视频,我怀疑我可能需要在播放视频之前将视频保存在本地。

我的相关代码如下:

//...
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];
    }
}

PS:通知处理程序moviePlayBackDidFinish总是在压缩视频后被调用,我得到一个空白屏幕。此外,记录moviePath变量给了我这种路径:

/private/var/mobile/Applications/5912AED1-S1DE-25EF-A8B-EF7AD21E3R65/tmp//trim.‌​uUcGJU.MOV

正如我所说,我想我怀疑直接从相机胶卷播放视频是不可能的。但我需要你确认。谢谢。

4

0 回答 0