如何在给定时间暂停看电影?IOS
我想在给定时间暂停一部电影,然后将一个动作继续多次。 我已经尝试过这样的 NSTimer:
#define Timer 0.05
#define Accuracy 0.025
pauseTimeArray = [NSArray arrayWithObjects:[NSNumber numberWithFloat:5.00],[NSNumber numberWithFloat:10.00],[NSNumber numberWithFloat:15.00] , nil];
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(timeAction) userInfo:nil repeats:YES];
- (void)timeAction{
if (_moviePlayer.playbackState == MPMoviePlaybackStatePlaying) {
NSNumber * positionNum = [NSNumber numberWithFloat:_moviePlayer.currentPlaybackTime];
float positionFloat = [positionNum floatValue];
for (NSNumber * pauseNum in _pauseTimeArray) {
float pauseFloat = [pauseNum floatValue];
float differentFloat = fabsf(pauseFloat - positionFloat);
if (differentFloat < Accuracy) {
[_moviePlayer pause];
}
}
}
}
当我暂停并再次播放时,它偶尔会暂停。和不同的Float <准确性。
有人可以在没有 NStimer 或其他东西的情况下提供另一个想法吗?谢谢!
I wanna pause a movie at a given time,and then an action to continue for many times.
i have try NSTimer like this:
#define Timer 0.05
#define Accuracy 0.025
pauseTimeArray = [NSArray arrayWithObjects:[NSNumber numberWithFloat:5.00],[NSNumber numberWithFloat:10.00],[NSNumber numberWithFloat:15.00] , nil];
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(timeAction) userInfo:nil repeats:YES];
- (void)timeAction{
if (_moviePlayer.playbackState == MPMoviePlaybackStatePlaying) {
NSNumber * positionNum = [NSNumber numberWithFloat:_moviePlayer.currentPlaybackTime];
float positionFloat = [positionNum floatValue];
for (NSNumber * pauseNum in _pauseTimeArray) {
float pauseFloat = [pauseNum floatValue];
float differentFloat = fabsf(pauseFloat - positionFloat);
if (differentFloat < Accuracy) {
[_moviePlayer pause];
}
}
}
}
And when i paused and play again , it occasionally paused. and the differentFloat < Accuracy.
could someone give another idear without NStimer,or something else.Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的方法很好,但需要一些改进才能正常工作。
不要在
pauseFloat
+/-Accuracy
范围内检查positionFloat
,而是保留上次暂停时间作为检查点。然后,如果positionFloat
大于此检查点 - 暂停影片并设置下一个检查点。当然,检查 currentCheckpoint 是否在您的pauseTimeArray范围内。
Your approach is good but it needs some improvements to work correctly.
Instead of checking
positionFloat
in range ofpauseFloat
+/-Accuracy
keep your last pause time, as checkpoint. Then ifpositionFloat
is greater than this checkpoint - pause movie and set next checkpoint.And of course, check if currentCheckpoint is inside your pauseTimeArray bounds.