我正面临着内存泄漏和其他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];
}发布于 2010-10-30 17:09:24
我不确定这是不是你的情况,但这是文档对MPMoviePlayerPlaybackDidFinishNotification的描述:
如果电影播放器在全屏模式下显示,并且用户点击了完成按钮,则不会发送此通知。在这种情况下,当播放器退出全屏模式时,完成按钮会导致影片播放暂停。如果要在代码中检测此场景,则应监视其他通知,如MPMoviePlayerDidExitFullscreenNotification。
似乎只有在电影停止时才会调用MPMoviePlayerPlaybackDidFinishNotification。如果您使用的是完成按钮,则应改用MPMoviePlayerDidExitFullscreenNotification。
发布于 2010-10-30 19:23:36
我试图通过传递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];
}https://stackoverflow.com/questions/4057864
复制相似问题