如何发布MPMoviePlayerController? [英] How to release MPMoviePlayerController?

查看:104
本文介绍了如何发布MPMoviePlayerController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个访问电影播放器​​的观点。我已将以下代码放在AppDelegate中用于这些视图的方法中。他们发送文件名进行播放。代码工作正常,但我知道某个地方需要发布。如果我将最后一行添加为发布或自动释放,则一旦用户在电影播放器​​上按下完成,应用程序将崩溃。

I have a couple of views that access the movie player. I've put the following code in a method in AppDelegate for these views. They send in the filename to play. The code works fine but I know a release is required somewhere. If I add the last line as a release or autorelease, the app will crash once the user presses done on the movieplayer.

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] 
                 initWithContentURL:[NSURL fileURLWithPath:moviePath]];
moviePlayer.movieControlMode = MPMovieControlModeDefault;
[moviePlayer play];
//[moviePlayer release];

我收到此错误:

objc [51051]:FREED(id):消息videoViewController发送到释放对象= 0x1069b30

objc[51051]: FREED(id): message videoViewController sent to freed object=0x1069b30

程序收到信号:EXC_BAD_INSTRUCTION。

Program received signal: "EXC_BAD_INSTRUCTION".

我应该如何发布播放器?

How should I be releasing the player?

推荐答案

我发现MPMoviePlayerController必须是在您可以安全地释放之前发送停止消息。所以我在handlePlaybackEnd中执行 - 首先我停止它,然后我自动释放它。调用发布似乎不太好:

What I've found is that the MPMoviePlayerController has to be sent the stop message before you can safely release it. So I do it in handlePlaybackEnd - first I stop it, then I autorelease it. Calling release doesn't seem to work too well:

- (void) moviePlayBackDidFinish : (NSNotification *) notification
{
  VideoPlayerController * player = notification.object;
  [player stop];
  [player autorelease];
}

整个事情变得有点棘手,因为MPMoviePlayerPlaybackDidFinishNotification可以发送超过曾经,但两次停止/自动发布也不会对你有任何帮助。所以你需要以某种方式防范它。

The whole thing becomes a bit trickier in that the MPMoviePlayerPlaybackDidFinishNotification can get sent more than once, but calling stop/autorlease twice won't do you any good either. So you need to guard against that somehow.

最后,它似乎需要主运行循环的几次迭代,直到你可以安全地创建一个新的MPMoviePlayerController实例。如果你做得太快,你会得到声音,但没有视频。好玩,呵呵?

Lastly, it seems to take a few iterations of the main run loop until you can safely create a new MPMoviePlayerController instance. If you do it too quickly, you'll get sound but no video. Great fun, huh?

这篇关于如何发布MPMoviePlayerController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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