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

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

问题描述

当我尝试从我的iPhone(位于documentsDirectory)播放视频时,使用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];


推荐答案

编辑 J.在发布下面的答案之后,我注意到无论何时重新分配控制器,错误都会在旧控制器自动解除分配时返回,即使我自己也没有设置任何通知处理程序。由于失败来自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.

作为脚注,如果你(比如)dealloc /在 MPMoviePlayerPlaybackDidFinishNotification 通知处理程序中手动'不引用'(设置为零)属性,然后您可能会注意到错误返回。所以不要这样做: - )

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天全站免登陆