Can't get movie to finish within loop

41 views Asked by At

I want a movie to play as often as there are objects in an array, but I want to make sure that the movie has finished playing each time.

Here's some -simplified- code that I'd expect to do just that:

- (void)loopThroughArray {

        [Array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            NSLog (@"Index = %i", idx);

            moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];

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


        }];
    }];

}


- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
    moviePlayerController = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:moviePlayerController];

    NSLog(@"Movie playback finished");
}

Unfortunately, the code just runs through the loop, after which is plays the movie, as seen in the logs:

 Index = 0
 Index = 1
 Index = 2
 Index = 3
 Index = 4
 Index = 5
 Movie playback finished

What am I doing wrong?

Thanks for your insights

0

There are 0 answers