我在iPhone应用程序中使用mpmovieplayercontroller来显示一些短视频片段。我取消了一个类别的声明,该类别向类中添加了两个方法,以便将其视图正确附加到特定视图并从中删除。
我使用通知系统让一个类知道电影何时播放完毕,然后我尝试删除它。
以下是类别中的方法:
- (void)setViewInCurrentController{
LPAppDelegate * appDelegate = [[UIApplication sharedApplication] delegate];
self.view.frame = CGRectMake(0, 0, 320, 480);
self.view.alpha = 0.0;
[appDelegate.window addSubview:self.view];
[UIView beginAnimations:@"FadeIn" context:nil];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.alpha = 1.0;
[UIView commitAnimations];
}
- (void)removeViewInCurrentController{
[UIView beginAnimations:@"FadeOut" context:nil];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.alpha = 0.0;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(removeFromSuperview)];
[UIView commitAnimations];
}
这里是我使用mpmovieplayer的地方:
- (void)playVideoNarration:(VideoNarration *)vNarr{
MPMoviePlayerController *player = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL fileURLWithPath:vNarr.videoURI]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(videoNarrationFinishedPlaying:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player setViewInCurrentController];
player.controlStyle = MPMovieControlStyleNone;
[player play];
}
- (void)videoNarrationFinishedPlaying:(NSNotification *) aNotification{
MPMoviePlayerController * player = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player removeViewInCurrentController];
[player release];
}
视频显示正确,然后播放器从视图中移除,我想它也会被释放,但是当我看到带有仪器分配工具的应用程序时,我看到分配的内存达到20+MB,并且在播放器完成后不会被释放。
负责分配的是一个名为videotoolbox的lib。
除了一个名为audio工具箱的库中的一些之外,没有显示任何泄漏。你猜怎么回事?