0

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

Sjakelien
  • 2,255
  • 3
  • 25
  • 43
  • what happen if you are used removeAll notification code? – Nitin Gohel Jun 10 '15 at 13:39
  • not sure what you mean, could you be more specific? – Sjakelien Jun 10 '15 at 13:46
  • i also not understand what is the issue :) you want dismiss movieplayer after finished ? – Nitin Gohel Jun 10 '15 at 13:48
  • Maybe my question is not clear: I want the movie to play until the end, before my loop continues. Let's say, the movie lasts 5 seconds, and there are 7 objects in my array, then the whole sequence would last for 5*7=35 seconds. – Sjakelien Jun 10 '15 at 13:49
  • oh you mean if there is 7 diff movie in to your array and you want continues play one by one without dismiss ? – Nitin Gohel Jun 10 '15 at 13:50
  • Check this : http://stackoverflow.com/questions/11823683/playing-multiple-videos-using-mpmovieplayercontroller – Nitin Gohel Jun 10 '15 at 13:52
  • well, in my case it's the same movie all over again, but yes, that is the idea – Sjakelien Jun 10 '15 at 13:52
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/80190/discussion-between-nitin-gohel-and-sjakelien). – Nitin Gohel Jun 10 '15 at 13:53
  • I think that link isn't relevant to my case: I have just one movie. I want the app to enter the loop, get to the first object in the array, play the movie completely, then, within the loop get to second object, play the (same!) movie from start till end, etc. – Sjakelien Jun 10 '15 at 13:58

0 Answers0