我遇到两种症状:
1)当我在我的[ourMovie release]
方法下方中调用movieFinished:
时,我被告知我发布了已发布的内容..不是[sentNotification object]
传递给 - movieFinished:
副本,因此我必须释放一些东西?
MPMoviePlayerPlaybackDidFinishNotification
添加NSNotification观察者时,电影不会显示。没有可检测到的错误,只是没有显示?我的目标是检测用户何时暂停或停止播放,然后按“主页”按钮将我的应用程序发送到后台。当应用程序返回前台时,我想继续用户在按下暂停或停止按钮时离开的电影..不要像我的应用现在那样从头开始。
在我继续之前,我在 AppDelegate 中确实有以下内容:
[notificationCenter addObserver:self
selector:@selector(pauseApp)
name:@"UIApplicationDidEnterBackgroundNotification"
object:ourApp];
仅供参考:我的-pauseApp最终会调用[ourMovie pause]
在我的-playVideo:方法中我有
[notificationCenter addObserver:self
selector:@selector(movieFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:ourMovie];
[notificationCenter addObserver:self
selector:@selector(pauseDownload)
name:@"MPMoviePlayerPlaybackStateDidChangeNotification"
object:ourMovie];
和我的-movieFinished方法我有
- (void )movieFinished:(NSNotification *)sentNotification
{
NSObject *theNotifyObject = [sentNotification object];
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
if ( [theNotifyObject isKindOfClass:[MPMoviePlayerController class]] )
{
MPMoviePlayerController *ourMovie = (MPMoviePlayerController *)theNotifyObject;
[notificationCenter removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:ourMovie];
[notificationCenter removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:ourMovie];
[ourMovie pause];
[ourMovie stop];
[ourMovie release]; // release what we don't own ???
}
}
答案 0 :(得分:0)
1)不,您不必释放ourMovie
。您没有复制任何东西,您只是将对象作为参数传递给方法,因此引用内存中的相同位置。因此,如果您在创建对象时之前的内存管理是正确的,那么此时您无需执行任何操作。
2)如果您希望视频在同一个地方播放,那么在stop
上致电pause
后,为什么要拨打ourMovie
?
这是来自Apple文档的MPMediaPlayBack stop
方法的引用:“此方法停止播放当前项目并将播放头重置为项目的开头。”强>