iOS multiple views and MPMoviePlayer issue
I have two view controllers, one is mainController second one is movieController...
After swiping back to mainController from movieController with [self.view removeFromSuperview];
video playing in movieController still plays as background sound.
I did release player, but no idea.
@synthesize viewForMovie,player;
- (void)viewDidLoad {
[super viewDidLoad];
//background image
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"mits_bg.png"]];
//gesture recognizer -to up
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleSwipes:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeGesture];
[swipeGesture release];
//movie player
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieDurationAvailable:)
name:MPMovieDurationAvailableNotification
object:nil];
**self.player = [[[MPMoviePlayerController alloc] init] autorelease];**
//self.player.controlStyle = MPMovieControlStyleNone; // no control at all :)
self.player.contentURL = [self movieURL];
self.player.view.frame = self.viewForMovie.bounds;
self.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight ;
[self.viewForMovie addSubview:player.view];
[self.player play];
}
//---gesture recognizer
- (IBAction) handleSwipes:(UIGestureRecognizer *) sender {
UISwipeGestureRecognizerDirection direction = [(UISwipeGestureRecognizer *) sender direction];
if (direction == UISwipeGestureRecognizerDirectionDown) {
CATransition *transition = [CATransition animation];
transition.duration = 0.75;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromBottom;
transition.delegate = self;
// Next add it to the containerView's layer. This will perform the transition based on how we change its contents.
[self.view.superview.layer addAnimation:transition forKey:nil];
[self.view removeFromSuperview];
**self.player = nil;**
//[player release]; // I give it a try like this also
}
}
- (void)viewDidUnload {
[s开发者_JAVA百科uper viewDidUnload];
self.viewForMovie = nil;
self.player = nil;
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[thumbnailScrollView release];
[viewForMovie release];
[onScreenDisplayLabel release];
[player release];
[super dealloc];
}
You are retaining twice when you do this,
self.player = [[MPMoviePlayerController alloc] init];
You should add an autorelease
message to this,
self.player = [[[MPMoviePlayerController alloc] init] autorelease];
I don't see a release called except for in viewDidUnload
and dealloc
. You should call it as soon as you remove the view from the superview. nil
ing is a better option as your release call in dealloc
will be on nil
rather than a deallocated object. So after removing it from the view, make it nil
like this,
self.player = nil;
精彩评论