【问题标题】:MPMoviePlayerController How pause .mov at specific breakpoints?MPMoviePlayerController 如何在特定断点暂停.mov?
【发布时间】:2014-01-10 11:50:01
【问题描述】:

我需要在我的 ios 6 应用中播放 .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];

            }
        }
    }
}

【问题讨论】:

  • 我对断点根本不触发的假设:给定的精度可能有点太紧了,0.01 意味着您希望计时器以第 100 秒的精度触发,常规计时器将最当然不匹配,因为它在主循环中运行。
  • 你解决了这个问题吗?

标签: ios mpmovieplayercontroller nstimer playback nsnotifications


【解决方案1】:
double loadTime =moviePlayerController.playableDuration;
double currentTime =moviePlayerController.currentPlaybackTime;
double totalTime =moviePlayerController.duration;

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

【讨论】:

  • OP 已经清楚地使用了 currentPlaybackTime,这有什么帮助。
猜你喜欢
  • 2019-01-05
  • 2011-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 2018-06-19
  • 1970-01-01
相关资源
最近更新 更多