views:

68

answers:

1

Hello,

I am developing an iPad app where I am playing the videos stored within the app itself. I am representing the list of videos in a table view. When I select a row, the video corresponding to that row plays. But while performing this, sometimes screen goes black , no video is visible but only audio is playing.

I am aware that making the video play in fullscreen mode or using the MPMoviePlayerViewController eliminates this problem. But my requirement is that I don't want to play the movie in fullscreen initially. Please guide me on how this can be achieved.

-(void)playMovie { MPMoviePlayerController *movieController = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl]; self.moviePalyer = movieController; [movieController release];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePalyerDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object: self.moviePalyer];

self.moviePalyer.view.frame = CGRectMake(240, 0, 561, 313); self.moviePalyer.view.backgroundColor = [UIColor clearColor]; [self.moviePalyer prepareToPlay]; [self.view addSubview: self.moviePalyer.view]; [self.moviePalyer play];

} -(void)moviePalyerDidFinish:(NSNotification*)notification { [moviePalyer.view removeFromSuperview]; [moviePalyer stop]; moviePalyer.initialPlaybackTime = -1.0;

[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePalyer]; [moviePalyer release]; moviePalyer = nil; }

Thnaks.

NOTE: This is on ipad simulator

A: 

I have solved the issue. Previously I was creating the MPMoviePlayerController for each of the row selection, and releasing it in the moviedidfinish notification method .But now, instead of creating movieplayercontroller for every row selection, I am reusing the MPMoviePlayerControler object which has been already created.

Following is the Code snippet:

-(void)playMovie
{
   if(self.moviePalyer == nil)
   {

    MPMoviePlayerController *movieController = [[MPMoviePlayerController alloc] initWithContentURL:url];
    self.moviePalyer = movieController;
    [movieController release];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePalyerDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePalyer];

    self.moviePalyer.repeatMode = MPMovieRepeatModeOne;
    self.moviePalyer.view.frame = CGRectMake(240, 0, 561, 313);
    self.moviePalyer.view.backgroundColor = [UIColor clearColor];
}
else 
{
    [self.moviePalyer setContentURL:url];
    [self stopMovie];
}
[self.view addSubview: self.moviePalyer.view];
[self.moviePalyer play];
   }
   -(void)stopMovie
   {
     [self.moviePalyer.view removeFromSuperview];
[self.moviePalyer stop];
self.moviePalyer.initialPlaybackTime = -1.0;
   }

I am releasing the moviePlayer object in the dealloc method.

Hope this helps who is having the same issue.

samben