Added total frames as well as current and total seconds of animation (#814)
Fixes #721
diff --git a/LottieSample/src/main/kotlin/com/airbnb/lottie/samples/PlayerFragment.kt b/LottieSample/src/main/kotlin/com/airbnb/lottie/samples/PlayerFragment.kt
index 3f8dc3e..3a3b3ed 100644
--- a/LottieSample/src/main/kotlin/com/airbnb/lottie/samples/PlayerFragment.kt
+++ b/LottieSample/src/main/kotlin/com/airbnb/lottie/samples/PlayerFragment.kt
@@ -20,6 +20,7 @@
import androidx.view.children
import androidx.view.isVisible
import com.airbnb.lottie.L
+import com.airbnb.lottie.LottieAnimationView
import com.airbnb.lottie.LottieComposition
import com.airbnb.lottie.model.KeyPath
import com.airbnb.lottie.samples.model.CompositionArgs
@@ -182,8 +183,10 @@
))
animationView.repeatCount = ValueAnimator.INFINITE
+
animationView.addAnimatorUpdateListener {
- currentFrameView.text = animationView.frame.toString()
+ currentFrameView.text = updateFramesAndDurationLabel(animationView)
+
if (seekBar.isPressed) return@addAnimatorUpdateListener
seekBar.progress = ((it.animatedValue as Float) * seekBar.max).roundToInt()
}
@@ -522,4 +525,19 @@
}
}
}
+
+ private fun updateFramesAndDurationLabel(animation: LottieAnimationView): String {
+ val currentFrame = animation.frame.toString()
+ val totalFrames = ("%.0f").format(animation.maxFrame)
+
+ val animationSpeed: Float = Math.abs(animation.speed)
+
+ val totalTime = ((animation.duration / animationSpeed) / 1000.0)
+ val totalTimeFormatted = ("%.1f").format(totalTime)
+
+ val progress = (totalTime / 100.0) * (Math.round(animation.progress * 100.0))
+ val progressFormatted = ("%.1f").format(progress)
+
+ return "$currentFrame/$totalFrames\n$progressFormatted/$totalTimeFormatted"
+ }
}
\ No newline at end of file
diff --git a/LottieSample/src/main/res/layout/control_bar_player_controls.xml b/LottieSample/src/main/res/layout/control_bar_player_controls.xml
index 75f35c3..f909bb2 100644
--- a/LottieSample/src/main/res/layout/control_bar_player_controls.xml
+++ b/LottieSample/src/main/res/layout/control_bar_player_controls.xml
@@ -36,8 +36,8 @@
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:orientation="horizontal"
- android:paddingBottom="16dp"
- android:paddingTop="16dp">
+ android:paddingBottom="12dp"
+ android:paddingTop="12dp">
<RelativeLayout
android:layout_width="wrap_content"
@@ -58,7 +58,7 @@
android:layout_height="wrap_content"
android:layout_below="@id/playButton"
android:layout_centerHorizontal="true"
- android:layout_marginTop="8dp"
+ android:layout_marginTop="16dp"
android:text="0"
android:textColor="#464646"
android:textSize="10sp"/>