MPMoviePlayerController如何在特定断点处暂停.mov?

时间:2014-01-10 11:50:02

标签: ios mpmovieplayercontroller nstimer playback nsnotifications

我需要在ios 6 app中播放.mov。

您知道如何根据特定的时间点暂停和停止它吗?

我尝试使用 NSTimer ,每隔x秒触发一次checkCurrentPlabackTime动作,检查断点列表..

但它不准确! 有时它并没有停在我想要的地方......其他一些根本就没有停止

#define kTimer 0.01
#define kAccuracy 0.01

- (void)viewDidLoad
{

  [..]

 pauseTimeArray = [NSArray arrayWithObjects:
                  [NSNumber numberWithFloat:2.00]  ,
                  [NSNumber numberWithFloat:10.00] ,
                  [NSNumber numberWithFloat:12.30] ,
                  [NSNumber numberWithFloat:16.00] ,
                  [NSNumber numberWithFloat:18.80] ,
                  nil];

[NSTimer scheduledTimerWithTimeInterval:kTimer 
                                 target:self 
                               selector:@selector(timeAction) 
                               userInfo:nil repeats:YES];
}

- (void)timeAction{


// Check next breakpoint find the difference with the actual (Es. 02:00 - 00:00) -> I need you to stop again in 2 seconds



if (self.player.playbackState == MPMoviePlaybackStatePlaying) {

 //self.player is my mpMoviePlayerController instance
    NSNumber * positionNum = [NSNumber numberWithFloat:self.player.currentPlaybackTime];

    float positionFloat = [positionNum floatValue];
    NSLog(@"positionFloat:%f",positionFloat);

    for (NSNumber * pauseNum in pauseTimeArray) {

        float pauseFloat = [pauseNum floatValue];

        float differentFloat = fabsf(pauseFloat - positionFloat);

        if (differentFloat < kAccuracy) {
            [self.player pause];

           NSDictionary * dicInfo = [[NSDictionary alloc] initWithObjectsAndKeys:pauseNum,@"pauseIndex", nil];
           [[NSNotificationCenter defaultCenter]
                            postNotificationName:LSMoviePlayerPlaybackDidPauseNotification
                                          object:self
                                        userInfo:dicInfo];

            }
        }
    }
}

1 个答案:

答案 0 :(得分:-1)

double loadTime =moviePlayerController.playableDuration;
double currentTime =moviePlayerController.currentPlaybackTime;
double totalTime =moviePlayerController.duration;

您可以使用当前时间暂停MPMoviewplayercontroller特定时间