Round a frame when setting a value and retrieving a frame
Previously, frames were casted to ints/logs. However, this caused
them to be successaptable to floating point issues in which a frame
may be 49.99998 and rounded down to 49. Rounding the number should
produce more reliable frame calculations.
Fixes #591
diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
index ea0b458..209cd72 100644
--- a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
+++ b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
@@ -500,7 +500,7 @@
return 0;
}
- return (int) (getProgress() * composition.getDurationFrames());
+ return Math.round((getProgress() * composition.getDurationFrames()));
}
public void setProgress(@FloatRange(from = 0f, to = 1f) float progress) {
diff --git a/lottie/src/main/java/com/airbnb/lottie/utils/LottieValueAnimator.java b/lottie/src/main/java/com/airbnb/lottie/utils/LottieValueAnimator.java
index fd1fe91..18b46b7 100644
--- a/lottie/src/main/java/com/airbnb/lottie/utils/LottieValueAnimator.java
+++ b/lottie/src/main/java/com/airbnb/lottie/utils/LottieValueAnimator.java
@@ -51,7 +51,7 @@
float range = Math.abs(maxValue - minValue);
float animatedPercentage = distFromStart / range;
if (getDuration() > 0) {
- setCurrentPlayTime((long) (getDuration() * animatedPercentage));
+ setCurrentPlayTime(Math.round(getDuration() * animatedPercentage));
}
}