在iOS 5中使用MPMoviePlayerController在视频中重复场景的最佳方法?

时间:2022-09-07 11:04:43

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.

我想多次重复视频中的几个场景。在iOS 4中,我可以实现它并且它可以工作。在iOS 5中,代码不再以相同的方式工作。

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.

这是一个例子:场景1:从15秒到30秒开始。场景1重复5次。场景2:从45秒到55秒开始。场景2重复3次。

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

在iOS 5中,场景1重复5次。场景2将不再播放。

That's how I solved it for iOS 4:

这就是我为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
    }
}

1 个解决方案

#1


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.

我建议你试试AVPlayer Class(这里是Apple的文档)。这个类允许你使用像addBoundaryTimeObserverForTimes这样的方法:queue:usingBlock:和addPeriodicTimeObserverForInterval:queue:usingBlock:这两个方面都很有用。

#1


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.

我建议你试试AVPlayer Class(这里是Apple的文档)。这个类允许你使用像addBoundaryTimeObserverForTimes这样的方法:queue:usingBlock:和addPeriodicTimeObserverForInterval:queue:usingBlock:这两个方面都很有用。