无法使用MPMoviePlayerController运行视频文件?

时间:2012-03-16 10:03:58

标签: objective-c ios video xcode4 mpmovieplayercontroller

这是我的代码

-(IBAction)playvideo:(id)sender
{
NSLog(@"Get in");
    NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"video3" ofType:@"MOV"];
MPMoviePlayerController *movie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
    NSLog(@"movie path %@",moviePath);
    NSLog(@"movie %@",movie);
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieViewFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:movie];
    movie.controlStyle = MPMovieControlStyleDefault;
    movie.shouldAutoplay = YES;
    [self.view addSubview:movie.view];
    [movie setFullscreen:YES animated:YES];
    [movie play];
}

这是我的日志

  

2012-03-16 16:54:39.080 TestVideofile [510:11f03]来源2012-03-16   16:54:39.303 TestVideofile [510:11f03]电影之路   / Users / crazyoxy / Library / Application Support / iPhone   模拟器/ 5.1 /应用/ 7F1425B8-6DB0-4A09-AC8F-3BCDBF19ED95 / TestVideofile.app / video3.MOV   2012-03-16 16:54:39.304 TestVideofile [510:11f03]电影<   MPMoviePlayerController:0x7a8ea30>

单击与此IBAction链接的按钮后,它将变为黑色页面但未显示视频甚至任何音频。

你能帮我吗?

1 个答案:

答案 0 :(得分:3)

您正在使用ARC,如果不存在其他参考,播放器将被释放。

将它作为属性添加到ViewController实例只要ViewController是实例就会使实例保持活动状态。