0

I have an app where I play a movie after a touch on the view and then when the movie is finished. I place a button on the view. On clicking the button a second movie plays. But it seems that it is only then loaded and a short black screen appears. I want to avoid the black screen now...

Heres the code:

Initialization in viewDidLoad

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

NSString *movpath = [[NSBundle mainBundle] 
                     pathForResource:@"movie1" 
                     ofType:@"m4v"];

mpviewController = 
[[MPMoviePlayerViewController alloc]
 initWithContentURL:[NSURL fileURLWithPath:movpath]]; 

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


mp = [mpviewController moviePlayer];
// [mp setMovieControlMode:MPMovieControlModeHidden];
// [mp.view setFrame:CGRectMake(0, 0, 250, 263)]; 
mp.controlStyle = MPMovieControlStyleNone;    
mp.shouldAutoplay = NO;

[mp prepareToPlay];
[mp pause];

then on a storyboard touch I call startAnimation

- (IBAction)startAnimation:(id)sender {

     NSLog(@"Animation 1");  
    [self.view addSubview:mpviewController.view];
    [mp play];
}

after this movie finishes I set the button

- (void) movieFinishedCallback:(NSNotification*) aNotification {
   NSLog(@"...movie done");

// generate start button for animation 2
startAnimation2Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
startAnimation2Button.tag = 1;
[startAnimation2Button addTarget:self action:@selector(startAnimation2:) forControlEvents:UIControlEventTouchUpInside];
startAnimation2Button.frame = CGRectMake(130, 230, 070, 070);
startAnimation2Button.userInteractionEnabled = YES;
startAnimation2Button.alpha = 0.1;

[self.view addSubview:startAnimation2Button];
}

then after a touch on the button, the second animation starts

- (IBAction)startAnimation2:(id)sender  {

    NSLog(@"Animation 2");
    NSString *movpath = [[NSBundle mainBundle] 
                     pathForResource:@"movie2" 
                     ofType:@"m4v"];
    [mp setContentURL:[NSURL fileURLWithPath:movpath]];

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

    [mp play];
}

but here a short black screen appears, probably while movie2 is loaded and is then playing.

How can I avoid the black screen?

Greetz

spankmaster79
  • 21,555
  • 10
  • 42
  • 73

1 Answers1

1

You will not be able to entirely get rid of the pre buffering delay (black phase) between the videos when using MPMoviePlayerController.

Use AVQueuePlayer instead.

AVQueuePlayer is a subclass of AVPlayer you use to play a number of items in sequence.

See other questions and issues on that matter.

Community
  • 1
  • 1
Till
  • 27,559
  • 13
  • 88
  • 122
  • I'll try that one, althogh one comment bugs me... "As of iOS 5, it appears that AVQueuePlayer no longer pre-buffers. It did pre-buffer the next track in iOS 4." – spankmaster79 Mar 08 '12 at 12:45
  • 1
    it did work for me. I have a problem placing a button on the finished video, but it seems that's another problem – spankmaster79 Mar 19 '12 at 09:27