【问题标题】:MPMoviePlayerController not releasedMPMoviePlayerController 未发布
【发布时间】:2011-03-11 00:12:59
【问题描述】:

我正在 MPMoviePlayerController 中运行介绍影片,但我遇到了分配的内存未释放的问题。
影片结束后,Instruments 会显示正在释放的内存。
但是,当我通过点击它来跳过电影时,内存不会被释放。
以下是我的代码的重要部分:

- (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];
...
}

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

【问题讨论】:

    标签: iphone objective-c cocoa mpmovieplayercontroller


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-01-11
      • 1970-01-01
      • 2015-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-15
      • 1970-01-01
      相关资源
      最近更新 更多