【发布时间】:2015-08-19 11:07:40
【问题描述】:
我正在使用 AVPlayer 从本地读取视频。当我浏览视频时,有时我会看到几秒钟的像素化视频或出现一段时间的绿屏。
以下是我的擦洗代码:
- (void)playerControlView:(PlayerControlView *)playerControlView beganScrubbingAtPercent:(float)timePercent
{
if (_avPlayer.rate > 0) {
_resumePlayAfterScrub = YES;
} else {
_resumePlayAfterScrub = NO;
}
}
- (void)playerControlView:(PlayerControlView *)playerControlView scrubbedToPercent:(float)timePercent
{
if (_avPlayer.rate > 0) {
[_avPlayer pause];
[_loadingView startAnimating];
}
float durationSeconds = CMTimeGetSeconds(_avPlayerItem.duration);
CMTime cmTime = CMTimeMakeWithSeconds(durationSeconds * timePercent, NSEC_PER_SEC);
[_avPlayer seekToTime:cmTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
[_hideControlsTimer invalidate];
}
- (void)playerControlView:(PlayerControlView *)playerControlView finishedScrubbingAtPercent:(float)timePercent
{
if (_resumePlayAfterScrub) {
[_avPlayer play];
}
[self resetCurrentEventWithCopy:YES];
}
上面的代码我可以优化什么?
【问题讨论】: