开发者

MPMoviePlayerController keeps playing after view did unload?

I have a detail view, and when viewdidload in detailviewcontroller, MPMoviePlayerController allocs and plays an audio, but even if I navigate backto main table, audio is still being played.

How can I stop MPMovieplayercontroller when I navigate back to main table ? This is my MPMoviePlayerController code:

.h

MPMoviePlayerController *player;

.m

- (void)viewDidLoad
{
[super viewDidLoad];
//Get the Movie
NSURL *movieURL = [NSURL URLWithString:@"some link"];
player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

//Place it in subview, else it won’t work
player.view.frame = CGRectMake(20, 20, 280, 25);
player.backgroundView.backgroundColor = [UIColor clearColor];
[self.view addSubview:player.view];

// Play the movie.
[player play];

}

I even added following code into viewdidunload method, but didn't work.

- (void)viewDidUnload {

[player stop];
player.initialPlaybackTime = -1;
[player release];

// Release any retained subviews of the main view.
// e.开发者_StackOverflow社区g. self.myOutlet = nil;
}

What do you guys suggest ?

Thanks in advance,


I liked the user experience of viewDidDisappear better than viewWillDisappear. The animation starts and the movie stops after - the audio flows better for me this way.

-(void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [_moviePlayer stop];
}


I am having a similar issue. I am unable to use "viewDidDisappear" or "viewWillDisappear" because I have a "config" type view that can be opened while the content is playing, and it will trigger those two methods.

EDIT: Found that viewDidUnload and viewWillUnload are not getting called any more (I'm currently on an iOS 6+ device)...

From the documentation:

Availability: iOS (3.0 and later) Deprecated: Views are no longer purged under low-memory conditions and so this method is never called.

I just created a simple function called unload, and inside the function, set any objects I needed to = nil (I'm using ARC). At the time that I make the call to remove the view, I call the unload function as well. Hope it helps someone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜