MPMoviePlayerController未发布

时间:2010-07-02 08:50:47

标签: iphone objective-c cocoa mpmovieplayercontroller

我正在MPMoviePlayerController中运行一个介绍影片,我遇到的问题是分配的内存没有被释放。
当电影结束时,乐器会显示正在释放的内存 然而,当我通过点击它跳过电影时,内存不会被释放 以下是我的代码的重要部分:

- (void)applicationDidFinishLaunching:(UIApplication *)theApplication {
self.application = theApplication; 
NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"mymovie.mov" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
[window addSubview:moviePlayer.view];


moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.view.frame = window.frame;


UIView *introFrontView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
introFrontView.userInteractionEnabled = YES;
introFrontView.opaque = NO;
introTabRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self 
             action:@selector(introTabFrom:)];
[introFrontView addGestureRecognizer:introTabRecognizer];
[moviePlayer.view addSubview:introFrontView];
[introFrontView release];
[introTabRecognizer release];
self.moviePlayerController = moviePlayer;
[moviePlayer release];
[[NSNotificationCenter defaultCenter] addObserver:self 
        selector:@selector(introFinished:) 
         name:MPMoviePlayerPlaybackDidFinishNotification 
          object:self.moviePlayerController];
[self.moviePlayerController play];
}

- (void)introTabFrom:(UITapGestureRecognizer*)recognizer{
[[NSNotificationCenter defaultCenter] postNotificationName:MPMoviePlayerPlaybackDidFinishNotification
          object:self.moviePlayerController];
}

- (void) introFinished:(NSNotification*)notification {
[[NSNotificationCenter defaultCenter] removeObserver:self
         name:MPMoviePlayerPlaybackDidFinishNotification
          object:self.moviePlayerController];
[self.moviePlayerController pause];
[self.moviePlayerController stop];
[self.moviePlayerController release];
...
}

有什么我忘记的吗?
据我所知,我发布了正确的通知......
有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您可能想要注册MPMoviePlayerPlaybackStateDidChangeNotification,并查看传入的playbackState。