当ARC打开时,我无法播放视频(视频正在加载)。当ARC关闭时,我可以成功播放视频。我不知道为什么以及如何编辑我的代码以使用ARC播放视频on.Here是我的代码
-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"big-buck-bunny-clip" ofType:@"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
}
答案 0 :(得分:0)
有几种方法:
CFRetain()
手动保留它(此CoreFoundation函数将在Objective-C对象上执行其工作而不会触发ARC错误。请记住在完成其工作后立即检索它并CFRelease()
它。)-fno-objc-arc
标记此文件。 (这会让你的代码像地狱一样泄漏内存。)