简体   繁体   中英

How to get total number of frames available in the Lottie Animation?

I'm using random Lottie animation in my android app. I need to know the total number of frames used in the Lottie animation. depending upon the total frames, I want to loop the animation from 1st frame to the certain frame. for eg. If the Lottie file contains 60 frames then I want to perform the animation from 1 to any number < 60.

I'm using below dependency

implementation 'com.airbnb.android:lottie:3.4.2'

You can see the first and last frame counts in the json file. ip=first frame and op: last frame.

example image

Use addLottieOnCompositionLoadedListener to get your lottie's Composition .

binding.myLottie.addLottieOnCompositionLoadedListener { composition ->
    val startFrame = composition.startFrame
    val endFrame = composition.endFrame
    //will log start/end frame values
    Log.d(TAG, "startFrame : $startFrame, endFrame : $endFrame") 
}

Then to specific part of an animation use setMinAndMaxFrame()

binding.myLottie.addLottieOnCompositionLoadedListener { composition ->
    val startFrame = composition.startFrame
    val endFrame = composition.endFrame
    if (maxFrame < endFrame) {
        binding.myLottie.setMinAndMaxFrame(1, maxFrame)
    }
}

read here more about looping a specific part of an animation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM