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
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With