views:

91

answers:

2

I am using the MPMoviePlayerController to play a movie from the web. Depending on the table row selected a different movie is loaded. However, i would like the MPMoviePlayerController to disappear (or hide itself), once a new row is selected.

Here is the code that gets called to play my movie and to, eventually, hide it

- (IBAction) playMovie{
NSURL *url = [NSURL URLWithString:vidMovie];
moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];  
moviePlayer.view.frame = vidPlayer.frame;// CGRectMake(64, 624, 640, 360);
[self.view addSubview:moviePlayer.view];
[moviePlayer play];
}

- (void) hidePlayer{
[moviePlayer stop];
[moviePlayer release];
}

in my .h i declare moviePlayer as such

MPMoviePlayerController *moviePlayer;

I've tried setting the moviePlayer frame height and width to 0 but that still shows the play button.
I've tried the variables .hidden and .opaque and still i get nothing

Could anyone help me figure out what i might have forgotten. Any help would be greatly appreciated! Thanks

A: 

I found it after trying all sorts of different things...

Seems i needed to retain my moviePlyer to be able to remove it in another part of my code. If anyone has the same problem, here is my solution!

- (IBAction) playMovie{
NSURL *url = [NSURL URLWithString:vidMovie];
moviePlayer = [[[MPMoviePlayerController alloc]initWithContentURL:url] retain]; 
moviePlayer.view.frame = vidPlayer.frame;// CGRectMake(64, 624, 640, 360);
[self.view addSubview:moviePlayer.view];
[moviePlayer play];
}

- (void) hidePlayer{
[moviePlayer stop];
[moviePlayer.view removeFromSuperview];
}

Hope this might be able to help othes!

Steph Moreau
A: 

I'm curious. How were you able to get it to work when MPMoviePlayerController is not a subclass of UIViewController?

I am having the same problem. I need to put the video inside a view so I can subview it to another view and apply layout.

Thanks in advance.

chalcopyrite