视频未完全播放时,MPMoviePlayerController内存未释放

时间:2011-03-15 07:22:33

标签: iphone mpmovieplayercontroller

在ipad中播放视频时使用MPMoviePlayerController分配的大内存。如果视频播放结束时释放内存,但是当离开视图而没有视频结束时,分配的内存未完全释放。当用户想要导航时,我想释放与播放器关联的所有内存从视图(即使视频没有播放到最后)。请指导我如何实现这一目标。

- (void)playMovieAtURL:(NSURL *)theURL

{

   player = [[MPMoviePlayerController alloc] initWithContentURL:theURL];

   CGRect frame= CGRectMake(0.0,60.0,768.0,650.0);

   [[player view] setFrame:frame]; 

   [[NSNotificationCenter defaultCenter] addObserver:self     selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];   

   [self.view addSubview:player.view];

   [player play];

}

- (void)moviePlayBackDidFinish:(NSNotification *)通知{

[player.view removeFromSuperview];
[player stop];
player.initialPlaybackTime = -1.0;
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player] ;
[player release];
player=nil;

}

下面给出了获取像viedo或图片

这样的不同幻灯片的功能

- (无效)getSlide

{     if(玩家!=无)     {

    if(urlp !=nil)
    {
        [urlp release];
        urlp=nil;

    }
    [player pause];
    [player stop];

}

..... .... ....

 if(type =video)

   {
          urlp =[[NSURL alloc] initFileURLWithPath:toPlay];
          [self playMovieAtURL:urlp];
          [urlp release];


    }

}

1 个答案:

答案 0 :(得分:0)

我认为[player release];player = nil;应该这样做。确保在导航到另一个视图之前执行此操作。