我正在使用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];
}
我可以对上述代码进行优化吗?
答案 0 :(得分:0)
可能是连续IDR帧之间的间隙很高的情况,因此当您寻找时,需要一段时间才能达到最接近的IDR帧并清除图像缓冲区。直到播放器击中IDR帧,它才能正确解码流,这将导致您看到绿屏和像素化。