iOS 5 AVPlayerItem 的一个实例被释放 [英] iOS 5 an instance of AVPlayerItem was deallocated

查看:27
本文介绍了iOS 5 AVPlayerItem 的一个实例被释放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试从我的 iPhone(位于文档目录中)播放视频时,我在使用 iOS 5 时收到以下错误,而它在 iOS 4.3 上运行良好:

When I try to play a video from my iPhone (located in the documentsDirectory), I get the following error using iOS 5 while it was working fine with iOS 4.3:

类 AVPlayerItem 的实例 0x168da0 已被释放,而键值观察者仍向其注册.观察信息被泄露,甚至可能被错误地附加到其他对象上.在 NSKVODeallocateBreak 上设置断点以在调试器中停止.这是当前的观察信息:(上下文:0x0,属性:0x10b570>上下文:0x0,属性:0x117ab0>

An instance 0x168da0 of class AVPlayerItem was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info: ( Context: 0x0, Property: 0x10b570> Context: 0x0, Property: 0x117ab0>

这里是代码摘录:

MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[appDelegate.mediaManager loadVideo:[element valueForAttributeNamed:@"value"]]];  

        //create a NSNotificationCenter which call moviePlaybackComplete function when video playback finished
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];  

        //display the moviePlayer view
        [self.view addSubview:moviePlayerController.view];
        moviePlayerController.fullscreen = YES;  
        [moviePlayerController play];

推荐答案

编辑:在下面发布答案后,我注意到每当重新分配控制器时,错误就会返回为即使我自己绝对没有设置任何通知处理程序,旧控制器也会自动释放.由于故障来自 MP 框架内的代码,我会说这似乎是一个操作系统错误.

我在使用 ARC 的基于故事板的 iOS 5 项目中遇到了同样的问题.问题是在堆栈上使用临时变量来引用电影控制器——在我的例子中,我假设与 ARC 交互,但它可能比这更基本.无论如何,看起来某些东西被释放/丢失得太早(例如,当发生播放错误时)并且日志被您描述的那种输出填满.

I encountered the same issue with a storyboard-based iOS 5 project using ARC. The problem is the use of a temporary variable on the stack to refer to the movie controller - in my case I assumed an interaction with ARC, but it may be more fundamental than that. In any event, it looks as if something gets deallocated/lost too early (e.g. when a playback error occurs) and the log gets filled with the sort of output you describe.

在我的情况下,将电影控制器引用存储在所属类中定义的属性中解决了这个问题;即:

Storing the movie controller reference in a property defined within the owning class solved this in my case; i.e:

@interface MyClass
@property ( strong, nonatomic ) MPMoviePlayerViewController * movieController;
@end

@@implementation MyClass
@synthesize movieController = _movieController;

// ...then later, this:
//
// MPMoviePlayerController *moviePlayerController = [...];
//
// ...becomes:

self.movieController = [...];

如果您对属性使用合成访问器,那么无论您是使用手动还是自动引用计数,生成的 setter 方法都应该在设置新的之前正确释放旧的电影控制器(如果有的话).

If you're using synthesised accessors for the property then whether you're using manual or automatic reference counting the generated setter method should correctly deallocate the old movie controller (if there is one) before setting up the new one.

作为脚注,如果您(比如说)在 MPMoviePlayerPlaybackDidFinishNotification 通知处理程序中手动处理该属性(例如)dealloc/'unreference'(设置为零),那么您可能会注意到错误又回来了.所以不要那样做:-)

As a footnote, if you (say) dealloc/'unreference' (set-to-nil) the property manually in a MPMoviePlayerPlaybackDidFinishNotification notification handler then you'll probably notice that the errors come back. So don't do that :-)

这篇关于iOS 5 AVPlayerItem 的一个实例被释放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆