diff --git a/SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m b/SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m index 4d7a3155..f54812d2 100644 --- a/SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m +++ b/SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m @@ -25,6 +25,7 @@ @interface SGVideoRenderer () NSUInteger framesFetched; NSUInteger framesDisplayed; NSTimeInterval currentFrameEndTime; + NSTimeInterval currentFrameBeginTime; } _flags; SGCapacity _capacity; } @@ -198,6 +199,8 @@ - (BOOL)close self->_flags.hasNewFrame = NO; self->_flags.framesFetched = 0; self->_flags.framesDisplayed = 0; + self->_flags.currentFrameEndTime = 0; + self->_flags.currentFrameBeginTime = 0; self->_capacity = SGCapacityCreate(); return ^{b1();}; }, ^BOOL(SGBlock block) { @@ -252,6 +255,8 @@ - (BOOL)flush self->_flags.hasNewFrame = NO; self->_flags.framesFetched = 0; self->_flags.framesDisplayed = 0; + self->_flags.currentFrameEndTime = 0; + self->_flags.currentFrameBeginTime = 0; return nil; }, ^BOOL(SGBlock block) { self->_metalView.paused = NO; @@ -326,6 +331,7 @@ - (void)fetchTimerHandler self->_currentFrame = newFrame; self->_flags.hasNewFrame = YES; self->_flags.framesFetched += 1; + self->_flags.currentFrameBeginTime = currentMediaTime; self->_flags.currentFrameEndTime = currentMediaTime + CMTimeGetSeconds(duration); if (self->_frameOutput) { [newFrame lock]; @@ -338,7 +344,12 @@ - (void)fetchTimerHandler [self->_clock setVideoTime:time]; }; } else if (currentMediaTime < self->_flags.currentFrameEndTime) { + CMTime time = self->_currentFrame.timeStamp; + time = CMTimeAdd(time, SGCMTimeMakeWithSeconds(currentMediaTime - self->_flags.currentFrameBeginTime)); capacity.duration = SGCMTimeMakeWithSeconds(self->_flags.currentFrameEndTime - currentMediaTime); + b2 = ^{ + [self->_clock setVideoTime:time]; + }; } if (!SGCapacityIsEqual(self->_capacity, capacity)) { self->_capacity = capacity;