2

I am using this code to play a video on iOS 6:

-(void)GrommeVideo4
{
NSURL *url5 = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                      pathForResource:@"Flickers" ofType:@"mp4"]];
grommePlayer4 =  [[MPMoviePlayerController alloc]
                  initWithContentURL:url5];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayerWillExitFullscreen:)
                                             name:MPMoviePlayerWillExitFullscreenNotification
                                           object:nil];

grommePlayer4.controlStyle = MPMovieControlStyleDefault;
grommePlayer4.shouldAutoplay = YES;
[self.view addSubview:grommePlayer4.view];
[grommePlayer4 setFullscreen:YES animated:YES];
}

-(void) moviePlayBackDidFinish:(NSNotification *)aNotification{
[grommePlayer4.view removeFromSuperview];
grommePlayer4 = nil;
}


- (void)moviePlayerWillExitFullscreen:(NSNotification*) aNotification {
[grommePlayer4 stop];
[grommePlayer4.view removeFromSuperview];
grommePlayer4 = nil;
}

And I can press "Done" to exit the video at any time, and it works fine, but when I watch the video through to the end, it just displays a black screen. Any ideas as to why this could occur?

ToxicProxy
  • 199
  • 1
  • 4
  • 16

2 Answers2

2

try this, hope it helps

-(void)GrommeVideo4
{
    NSURL *url5 = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                      pathForResource:@"Flickers" ofType:@"mp4"]];
    grommePlayer4 =  [[MPMoviePlayerController alloc]
                  initWithContentURL:url5];

    grommePlayer4.controlStyle = MPMovieControlStyleDefault;
    grommePlayer4.shouldAutoplay = YES;
    [self.view addSubview:grommePlayer4.view];
    [grommePlayer4 setFullscreen:YES animated:YES];
}

-(void) moviePlayBackDidFinish:(NSNotification *)aNotification{
    [grommePlayer4.view removeFromSuperview];
    grommePlayer4 = nil;
}


- (void)moviePlayerWillExitFullscreen:(NSNotification*) aNotification {
    [grommePlayer4 stop];
    [grommePlayer4.view removeFromSuperview];
    grommePlayer4 = nil;
}
sabadow
  • 5,095
  • 3
  • 34
  • 51
Stanley
  • 36
  • 1
  • But wont I need to call the moviePlayBackDIdFinish using this line: `[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];` – ToxicProxy Nov 08 '12 at 15:45
0

Did you try to also stop the player in moviePlayBackDidFinish?

Kostis
  • 953
  • 9
  • 21