Check playRate in advance to avoid querying to frame duration

This commit is contained in:
DreamPiggy 2019-11-06 01:00:16 +08:00
parent 25e96717d6
commit 4e157a84f9
1 changed files with 7 additions and 6 deletions

View File

@ -228,17 +228,18 @@
NSUInteger currentFrameIndex = self.currentFrameIndex;
NSUInteger nextFrameIndex = (currentFrameIndex + 1) % totalFrameCount;
// Check if we have the frame buffer firstly to improve performance
if (!self.bufferMiss) {
// Then check if timestamp is reached
self.currentTime += duration;
NSTimeInterval currentDuration = [self.animatedProvider animatedImageDurationAtIndex:currentFrameIndex];
NSTimeInterval playRate = self.playRate;
if (playRate <= 0) {
// Does not support <= 0 play rate
[self stopPlaying];
return;
}
// Check if we have the frame buffer firstly to improve performance
if (!self.bufferMiss) {
// Then check if timestamp is reached
self.currentTime += duration;
NSTimeInterval currentDuration = [self.animatedProvider animatedImageDurationAtIndex:currentFrameIndex];
currentDuration = currentDuration / playRate;
if (self.currentTime < currentDuration) {
// Current frame timestamp not reached, return