tags:

views:

1074

answers:

1

Hi ,

Iam trying to play a video from a remote location and trying to overlay a window over the entire screen which is more or less transparent with few images along the edges . As soon as the movie is preloaded I play the video. This happens good the first time. But if I try to replay the video it does not play the video and neither am i able to click on the Play button from the controls of the player. I guess the overlay window is over the controls. How do i get the controls over the overlay window.

//- (void)moviePlayerContentPreloadDidFinish:(NSNotification *)notification{

NSLog(@"content preloaded");
NSDictionary *userInfo = [notification userInfo];
if ([userInfo valueForKey:@"error"]) {
 NSLog(@"*** An error occurred preloading the movie");
 return;
}

[self.spinner stopAnimating];

// Add the overlay view to the movie, so we can catch the clicks
OverlayViewController *ovc = [[OverlayViewController alloc] initWithNibName:@"OverlayView" bundle:nil];
self.overlayController = ovc;
[ovc release];
[self.overlayController setNextResponder:self];

MPMoviePlayerController *moviePlayer = [notification object];   


[moviePlayer play];

// Locate the movie player window
NSArray *windows = [[UIApplication sharedApplication] windows];
NSLog(@"window count= %d",[windows count]);
if ([windows count] < 2) {
 NSLog(@"*** Window for movie player is missing");
 return;
}

UIWindow *moviePlayerWindow = [windows objectAtIndex:1];
[moviePlayerWindow addSubview:self.overlayController.view];

}

The code that I use is

Am I doing something wrong. Is it possible to get the controls over the overlay or auto play it.

A: 

Two things. First, according to your code, in the moviePlayBackDidFinish method you must first release the moviePlayer and then instantiate it again with an alloc. You must do that every time you want to play a video.

MPMoviePlayerController *moviePlayer = [notification object];
[moviePlayer release]
...
MPMoviePlayerController *newMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: anURL];

The structure of your code works, but I think you should better have a look at the example provided by apple: http://developer.apple.com/iphone/library/samplecode/MoviePlayer_iPhone/index.html

Second, about the overlay, you are right, the overlay gets the events but you cannot put it under the movie player controls. What you have to do is to use the events you receive in your overlay to control the player. You could use touchesBegan event to pass the initial touch event and use it with the player (play, pause, stop).

Christian