我面临内存泄漏和其他MoviePlayer新启动的问题,因为我的MoviePlayer没有响应功能,我在完成按钮时释放该播放器。
(void) playMovieAtURL
{
MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoURL]];
mpViewController.view.backgroundColor = [UIColor blackColor];
[self presentMoviePlayerViewControllerAnimated:mpViewController];
[mpViewController.view setCenter:self.view.center];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mpViewController];
}
// When the movie is done,release the controller. (Doesn't come in it.)
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
MPMoviePlayerController* theMovie=[aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
// Release the movie instance created in playMovieAtURL
[theMovie release];
}
答案 0 :(得分:0)
不确定是你的情况,但这就是文档中关于MPMoviePlayerPlaybackDidFinishNotification的说法:
在案件中不发送此通知 电影播放器正在显示的位置 在全屏模式下,用户点按 完成按钮。在那种情况下, 完成按钮可以播放电影 播放器转出时暂停 全屏模式。如果你想 您可以在代码中检测到这种情况 应监控其他通知 如 MPMoviePlayerDidExitFullscreenNotification。
似乎MPMoviePlayerPlaybackDidFinishNotification仅在电影自动停止时调用。 如果您使用的是“完成”按钮,则应使用MPMoviePlayerDidExitFullscreenNotification。
答案 1 :(得分:0)
我试图通过传递nil来解决它,现在它正在回复我回调,但电影仍然没有发布,我也会尝试你的建议。无论如何我的新代码
-(void) playMovieAtURL
{
MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoURL]];
mpViewController.view.backgroundColor = [UIColor blackColor];
[self presentMoviePlayerViewControllerAnimated:mpViewController];
[mpViewController.view setCenter:self.view.center];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
}
// When the movie is done,release the controller.
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
MPMoviePlayerController* theMovie=[aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
// Release the movie instance created in playMovieAtURL
[theMovie release];
}