iPad iOS 4.2上的MPMoviePlayerViewController存在问题。应用程序播放视频,但当视频停止时,内存不会释放。 要创建视频播放器,我使用以下代码:
MPMoviePlayerViewController * videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:articleUrl];
[videoPlayer moviePlayer].movieSourceType = MPMovieSourceTypeFile;
[videoPlayer moviePlayer].controlStyle = MPMovieControlStyleDefault;
[videoPlayer moviePlayer].scalingMode = MPMovieScalingModeAspectFit;
[videoPlayer moviePlayer].fullscreen = NO;
self.playerViewController = videoPlayer;
[videoPlayer release];
videoPlayer = nil;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
MPMoviePlayerController *player = [playerViewController moviePlayer];
CGRect playerFrame = CGRectMake(20, 20, self.view.frame.size.width - 40, self.view.frame.size.height - 40);
player.view.frame = playerFrame;
[self.view addSubview:player.view];
[player play];
并且有movieFinishedCallback:方法代码:
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player.view removeFromSuperview];
[player release];
player = nil;
}
有人可以帮我吗?我已经阅读了很多与此问题相关的主题,但还没有找到解决方案。
答案 0 :(得分:0)
您的代码看起来不错 - 您的发布与您的保留等相匹配。
你有没有在仪器中运行它 - 即它绝对是泄漏?你怎么知道内存没有被释放?
视频播放框架没有任何问题,只要在短路时释放内存(即获得低内存警告),视频缓存就会缓存。尝试在模拟器中运行它并模拟内存警告 - 我打赌那时内存会被释放。
另外,你不知道它是否会在任何时候自动释放。
在遇到内存警告之前,我不会担心这个问题。在那之前,我只是假设视频框架知道它在做什么!