【发布时间】: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