8

I would like to reiterate several scenes from a video several times.
In iOS 4, I could implement it already and it works. In iOS 5, the code no longer works the same way.

Here's an example:
Scene 1: Starts at 15 seconds to 30 seconds.
Scene 1 is repeated 5 times.
Scene 2: Starts at 45 seconds to 55 seconds.
Scene 2 is repeated 3 times.

In iOS 5 scene 1 is repeated 5 times. Scene 2 will not play anymore.

That's how I solved it for iOS 4:

- (void)initMoviePlayer
{
    // Some other stuff…

   iterations = 5;

   NSDictionary *currentScene = [allScenes objectAtIndex:currentSceneIndex];

   moviePlayer.repeatMode = MPMovieRepeatModeOne;
   // Scene start time
   moviePlayer.initialPlaybackTime = [[currentScene objectForKey:@"StartTime"] intValue];
   // Scene end time
   moviePlayer.endPlaybackTime = [[currentScene objectForKey:@"EndTime"] intValue];

   [moviePlayer play];
}

// Called by MPMoviePlayerPlaybackStateDidChangeNotification
- (void)playerStateChanged:(NSNotification*)notification 
{
    // Some other stuff…

    if (counter == iterations)
    {
        currentSceneIndex++;

        // Stop movie
        [moviePlayer stop];

        // Init movie player with next scene
        [self initMoviePlayer];
    }
    else
    {
        counter++;

        // Scene will repeat because of MPMovieRepeatModeOne
    }
}
  • Not sure what code is missing from the // Some other stuff... section in the notification handler method, so I'm assuming you are checking for the appropriate playbackState value(s). I have noticed one difference with initialPlaybackTime on iOS5 over iOS4 which might be relevant here which affects playback of HLS streams over the net. On iOS4, providing a value for initialPlaybackTime started the video playback timeline from zero at this point whereas on iOS5, setting this value effectively cues to this point in the playback and starts from there. – reddersky Dec 05 '11 at 17:35
  • For example, setting an initialPlaybackTime of 30s in a 2 minute clip on iOS4 would start a timeline of 1m30s at zero. Whereas on iOS5 it starts a 2m timeline from 30s. – reddersky Dec 05 '11 at 17:39

1 Answers1

3

I suggest you to try the AVPlayer Class (here’s the documentation from Apple). This class allows you to use methods like addBoundaryTimeObserverForTimes:queue:usingBlock: and addPeriodicTimeObserverForInterval:queue:usingBlock: both interesting for your purpose.

Jorge Ramos
  • 891
  • 10
  • 21
  • Yeah, tanks for this tip. I used `addBoundaryTimeObserverForTimes:queue:usingBlock:` to set the times and than, when boundary reached, i used `seekToTime:` to seek to the next time stamp. – Artur Machura Jan 09 '12 at 09:54