我用:MPMoviePlayerController来显示视频.
下面我放了视频中的拇指列表.
当我按下拇指时,我想使用:setCurrentPlaybackTime跳转到视频中的特定位置.
我还有一个计时器根据视频的位置使用:currentPlaybackTime更新所选的拇指.
我的问题:当调用:setCurrentPlaybackTime时,玩家会在寻找特定秒之前继续给出秒数.玩家需要几秒钟来反映新的秒数.同时,用户的体验很糟糕:按下拇指显示它被选择用于显示时间,然后计时器更新到上一个拇指,然后它跳回到我选择的拇指.
我尝试使用(在计时器中):
if (moviePlayer.playbackState != MPMoviePlaybackStatePlaying && !(moviePlayer.loadState & MPMovieLoadStatePlaythroughOK)) return;
为了防止计时器更新所选的拇指,只要玩家处于显示前一个拇指和新拇指之间的过渡阶段,但它似乎不起作用. “playbackState”和“loadState”似乎是完全不稳定和不可预测的.
有任何想法吗?
最佳答案 为了解决这个问题,我在我的一个项目中实现了这个令人讨厌的状态覆盖.这是令人讨厌和脆弱的,但对我来说足够好.
我用了两面旗帜和两个时间间隔;
BOOL seekInProgress_;
BOOL seekRecoveryInProgress_;
NSTimeInterval seekingTowards_;
NSTimeInterval seekingRecoverySince_;
所有上述内容都应默认为NO和0.0.
在启动寻求时:
//are we supposed to seek?
if (movieController_.currentPlaybackTime != seekToTime)
{ //yes->
movieController_.currentPlaybackTime = seekToTime;
seekingTowards_ = seekToTime;
seekInProgress_ = YES;
}
在计时器回调中:
//are we currently seeking?
if (seekInProgress_)
{ //yes->did the playback-time change since the seeking has been triggered?
if (seekingTowards_ != movieController_.currentPlaybackTime)
{ //yes->we are now in seek-recovery state
seekingRecoverySince_ = movieController_.currentPlaybackTime;
seekRecoveryInProgress_ = YES;
seekInProgress_ = NO;
seekingTowards_ = 0.0;
}
}
//are we currently recovering from seeking?
else if (seekRecoveryInProgress_)
{ //yes->did the playback-time change since the seeking-recovery has been triggered?
if (seekingRecoverySince_ != movieController_.currentPlaybackTime)
{ //yes->seek recovery done!
seekRecoveryInProgress_ = NO;
seekingRecoverySince_ = 0.0;
}
}
最后,MPMoviePlayerController根本不是真正意义上的“微观管理”.在各种情况下,我不得不在国家报道中投入至少六打标志,我绝不会建议在其他项目中重复这一点.一旦达到这个级别,考虑使用AVPlayer可能是个好主意.