Iphone 检测MPMoviePlayerController何时暂停或停止
我有两种症状: 1) 当我在下面的Iphone 检测MPMoviePlayerController何时暂停或停止,iphone,ios,mpmovieplayercontroller,Iphone,Ios,Mpmovieplayercontroller,我有两种症状: 1) 当我在下面的movieFinished:method中调用[ourmovierelease]时,我被告知我正在发布一些已经发布的内容。。[sentNotification object]传递给–movieFinished:的不是副本,因此我必须发布一些东西吗 2) 与(1)完全无关的是,当为MPMoviePlayerPlaybackDidFinishNotification添加NSNotification观察员时,电影不会显示。没有可检测的错误,只是没有显示??我的目标是检
movieFinished:
method中调用[ourmovierelease]
时,我被告知我正在发布一些已经发布的内容。。[sentNotification object]
传递给–movieFinished:
的不是副本,因此我必须发布一些东西吗
2) 与(1)完全无关的是,当为MPMoviePlayerPlaybackDidFinishNotification
添加NSNotification观察员时,电影不会显示。没有可检测的错误,只是没有显示??我的目标是检测用户何时暂停或停止播放,然后按下Home按钮将我的应用程序发送到后台。当应用程序返回前台时,我想继续播放用户按下暂停或停止按钮时留下的电影。。不像我的应用程序现在那样从头开始
在继续之前,我的AppDelegate中确实有以下内容:
[notificationCenter addObserver:self
selector:@selector(pauseApp)
name:@"UIApplicationDidEnterBackgroundNotification"
object:ourApp];
仅供参考:my–pauseApp最终会调用[ourMovie pause]
在my–playVideo中:我拥有的方法
[notificationCenter addObserver:self
selector:@selector(movieFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:ourMovie];
[notificationCenter addObserver:self
selector:@selector(pauseDownload)
name:@"MPMoviePlayerPlaybackStateDidChangeNotification"
object:ourMovie];
- (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 ???
}
}
对于我的电影制作方法,我有
[notificationCenter addObserver:self
selector:@selector(movieFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:ourMovie];
[notificationCenter addObserver:self
selector:@selector(pauseDownload)
name:@"MPMoviePlayerPlaybackStateDidChangeNotification"
object:ourMovie];
- (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 ???
}
}
1) 不,您不必发布ourMovie
。您没有复制任何内容,只是将对象作为参数传递给方法,从而引用内存中的同一位置。因此,如果您以前的内存管理在创建对象时是正确的,那么此时您无需执行任何操作
2) 如果您希望在同一时间从同一地点播放视频,那么在您调用我们的电影上的暂停后,您为什么还要调用停止
这引用了苹果公司文档中的stop
方法:“此方法停止播放当前项目,并将播放头重置为项目的开头。”