检测 MPMoviePlayerController 何时暂停或停止
我遇到两种症状:
1) 当我在 movieFinished:
方法下面中调用 [ourMovie release]
时,我被告知我释放已经发布的东西..不是传递给 –movieFinished:
的 [sentNotification object]
副本,因此我必须释放一些东西?
2)与(1)完全无关的是,当为 MPMoviePlayerPlaybackDidFinishNotification
添加 NSNotification 观察者时,电影不会显示。没有可检测到的错误,只是没有出现?我的目标是检测用户何时暂停或停止播放,然后按下主页按钮将我的应用程序发送到后台。当应用程序返回前台时,我想继续播放用户按下暂停或停止按钮时留下的电影。而不是像我的应用程序现在那样从头开始。
在继续之前,我的 AppDelegate 中确实有以下内容:
[notificationCenter addObserver:self
selector:@selector(pauseApp)
name:@"UIApplicationDidEnterBackgroundNotification"
object:ourApp];
仅供参考:我的 –pauseApp 最终会调用 [ourMovie 暂停]
在我的 –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 ???
}
}
There are two symptoms I am experiencing:
1) when I call [ourMovie release]
in my movieFinished:
method below, I am told I am releasing something already released .. isn’t the [sentNotification object]
passed to –movieFinished:
a copy and therefore something I have to release ??
2) totally unrelated to (1) is that when add a NSNotification observer for MPMoviePlayerPlaybackDidFinishNotification
, the movie does not show up. No detectable error, just a no-show ?? My goal here is to detect when the user pauses or stops the playback and then pushes the Home button to send my app to the background. When the app returns to the foreground, I want to continue the movie where the user left it when he pushed the pause or stop button .. not start from scratch as my app does now.
Before I proceed, I do have the following in my AppDelegate:
[notificationCenter addObserver:self
selector:@selector(pauseApp)
name:@"UIApplicationDidEnterBackgroundNotification"
object:ourApp];
FYI: my –pauseApp eventually calls [ourMovie pause]
In my –playVideo: method I have
[notificationCenter addObserver:self
selector:@selector(movieFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:ourMovie];
[notificationCenter addObserver:self
selector:@selector(pauseDownload)
name:@"MPMoviePlayerPlaybackStateDidChangeNotification"
object:ourMovie];
and for my –movieFinished method I have
- (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 ???
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1) 不,您不必发布
ourMovie
。您没有复制任何内容,只是将对象作为参数传递给方法,因此引用内存中的同一位置。因此,如果您之前在创建对象时的内存管理是正确的,那么此时您无需执行任何操作。2) 如果您希望视频在同一时间点播放,那么为什么在
ourMovie
上调用pause
后还要调用stop
呢?这是来自 Apple 文档的引用 MPMediaPlayBack 的
stop
方法:"该方法停止当前项目的播放并重置播放头指向项目的开头。”1) No, you don't have to release
ourMovie
. You are not copying anything, you are just passing an object as an argument to a method, hence referencing the same place in memory. So if your previous memory management was correct when creating the object, you don't have to do anything at this point.2) If you want the video to play from the same place in time, then why are you calling
stop
after you callpause
onourMovie
?This a citation from Apple documentation on MPMediaPlayBack's
stop
method: "This method stops playback of the current item and resets the playhead to the start of the item."