Command Palette

Search for a command to run...

dotLottie Android Player API Reference

API reference for the dotLottie Android player. Details for Composable function, XML attributes, Widget class, Controller class, EventListener, types, and enums.

dotLottie Android Player API Reference

DotLottieAnimation Composable Function API

This page documents all parameters and methods for the Android player API, including the DotLottieAnimation composable, XML attributes, Widget class, Controller, EventListener interface, and all supporting types.

Parameters

ParameterDescriptionTypeDefault Value
modifierThe modifier to be applied to the animation view.ModifierModifier
source*The URL source of the animation.DotLottieSourcenull
autoplayDetermines if the animation will start playing automatically.Booleanfalse
loopDetermines whether the animation should loop.Booleanfalse
loopCountMaximum number of loop iterations (0 = infinite).UInt0u
useFrameInterpolationEnables or disables frame interpolation for smoother animation.Booleantrue
themeIdThe themeId to be loaded.Stringnull
markerThe segment name or marker to be played.Stringnull
speedThe playback speed of the animation.Float1f
segmentThe segment to be played.Pair<Float, Float>null
playModeThe play mode of the animation (e.g., forward, reverse).ModeMode.FORWARD
controllerThe controller for managing animation playback and state.DotLottieControllernull
layoutSets the the layout of the Animation.LayoutcreateDefaultLayout()
eventListenersA list of event listeners for animation events.List<DotLottieEventListener>emptyList()
stateMachineIdThe ID of a state machine to load automatically on init.String?null
threadsNumber of rendering threads.UInt?null

Functionality

  • Loading Animations: The DotLottieAnimation composable function supports loading animations from various sources, including URLs, asset files, raw resources, or raw data using the DotLottieSource type. At least one source must be provided (either via the source parameter or the controller).

  • Playback Control: The function integrates with DotLottieController for controlling animation playback, including play, pause, and stop functionalities. The autoplay and loop parameters provide initial playback behavior.

  • Customization: Parameters such as speed, playMode, useFrameInterpolation, marker, and segment allow for customization of the animation playback, including its speed, direction, smoothness, and specific parts to play.

  • Event Handling: The eventListeners parameter allows developers to attach multiple event listeners to handle various animation events, such as loading errors or completion, using the DotLottieEventListener interface.

  • Theming: The themeId parameter allows applying pre-defined themes packed within a .lottie file.

  • Layout: The layout parameter controls how the animation fits and aligns within the composable's bounds.

  • State Machine: The stateMachineId parameter allows a state machine to be loaded automatically when the animation loads.

Example Usage

import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.foundation.background
import com.lottiefiles.dotlottie.core.util.DotLottieSource
import com.dotlottie.dlplayer.Mode
import com.lottiefiles.dotlottie.core.widget.DotLottieController
import com.lottiefiles.dotlottie.core.model.DotLottieEventListener

DotLottieAnimation(
    modifier = Modifier.background(Color.LightGray),
    source = DotLottieSource.Url("https://lottie.host/294b684d-d6b4-4116-ab35-85ef566d4379/VkGHcqcMUI.lottie"),
    autoplay = true,
    loop = true,
    speed = 1.5f,
    playMode = Mode.FORWARD,
)

DotLottieAnimation XML Attributes

The DotLottieAnimation class utilizes a set of XML attributes for configuration within layout XML files. These attributes allow for the customization of animation properties directly from XML. Below is a table summarizing the available XML attributes and their functionalities:

XML AttributeDescriptionFormatDefault Value
dotLottie_srcSpecifies the source of the Lottie animation. This can be a local asset filename or a URL to a .lottie or .json file.stringNone
dotLottie_loopDetermines whether the animation should loop indefinitely.booleanfalse
dotLottie_playModeDefines the play mode of the animation when it reaches the end and the repeat count is greater than 0 or infinite.enumnormal (1)
dotLottie_speedAdjusts the playback speed of the animation. A value of 1.0 plays the animation at its normal speed, values greater than 1.0 speed up the playback, and values less than 1.0 slow it down.float1.0f
dotLottie_autoplayDetermines if the animation will start playing automatically upon loading.booleanfalse
dotLottie_backgroundColorSets the background color of the animation view.integerNone
dotLottie_useFrameInterpolationEnables or disables frame interpolation for smoother animation playback.booleantrue
dotLottie_themeIdSets the themeId to load.string""
dotLottie_stateMachineIdSets the state machine ID to load on initialization.string""
dotLottie_markerSets the marker to play.string""
dotLottie_animationIdSets the animation ID for multi-animation .lottie files.string""

These XML attributes provide a convenient way to configure DotLottieAnimation properties directly within layout files, offering flexibility in setting up animations without the need for additional code.


DotLottieAnimation Widget Class API Reference

This reference details the properties, methods, and events available in the com.lottiefiles.dotlottie.core.widget.DotLottieAnimation class (used with XML layouts), providing a comprehensive guide for developers to effectively utilize this class in their Android applications.

Properties

PropertyDescriptionTypeAccess
speedGets the playback speed of the animation.FloatRead
loopChecks if the animation is set to loop.BooleanRead
autoplayDetermines if the animation will start playing automatically.BooleanRead
isPlayingIndicates whether the animation is currently playing.BooleanRead
isPausedIndicates whether the animation is paused.BooleanRead
isStoppedIndicates whether the animation is stopped.BooleanRead
isLoadedChecks if the animation has been loaded successfully.BooleanRead
totalFramesGets the total number of frames in the animation.FloatRead
currentFrameGets the current frame of the animation.FloatRead
playModeGets the current play mode of the animation.ModeRead
segmentGets the start and end frames of the current segment being played.Pair<Float, Float>Read
durationGets the duration of the animation in seconds.FloatRead
loopCountGets the number of times the animation will loop.UIntRead
useFrameInterpolationChecks if frame interpolation is enabled for smoother animation.BooleanRead
markerGets the current marker of the animation.StringRead
markersGets the list of markers in the animation.List<Marker>Read
activeThemeIdRetrieves the ID of the currently active theme.StringRead
activeAnimationIdRetrieves the ID of the currently active animation.StringRead

Methods

MethodDescription
setFrame(frame: Float)Sets the animation to the specified frame.
setUseFrameInterpolation(enable: Boolean)Enables or disables frame interpolation for smoother animation playback.
setSegment(firstFrame: Float, lastFrame: Float)Defines a specific segment of the animation to play, specified by start and end frames.
setLoop(loop: Boolean)Sets whether the animation should loop.
freeze()Freezes the animation at the current frame, effectively pausing it.
unFreeze()Unfreezes the animation, allowing it to continue playing from the frozen frame.
setSpeed(speed: Float)Adjusts the playback speed of the animation.
play()Starts or resumes the animation playback.
stop()Stops the animation and resets it to the beginning.
setPlayMode(repeatMode: Mode)Sets the play mode of the animation (e.g., forward, reverse).
pause()Pauses the animation playback.
destroy()Releases resources associated with the animation.
load(config: Config)Loads the animation with the specified configuration.
resize(width: Int, height: Int)Resizes the animation view to the specified width and height.
addEventListener(listener: DotLottieEventListener)Adds an event listener to receive animation events.
removeEventListener(listener: DotLottieEventListener)Removes an event listener.
setTheme(themeId: String)Loads a theme by its ID.
setThemeData(themeData: String)Loads a theme from the provided theme data.
resetTheme()Resets the theme to the default theme.
loadAnimation(animationId: String)Loads a specific animation by ID from a multi-animation .lottie file.
manifest(): Manifest?Returns the dotLottie manifest.
setLoopCount(loopCount: UInt)Sets the number of times the animation loops.
setMarker(marker: String)Sets the animation to play from a named marker.
setLayout(fit: Fit, alignment: Pair<Float, Float>)Sets the layout fit and alignment for the animation.
setLayout(fit: Fit, alignment: LayoutUtil.Alignment)Sets the layout fit and alignment using the alignment enum.
setColorSlot(slotId: String, color: Int): BooleanSets a color slot value. Returns true on success.
setScalarSlot(slotId: String, value: Float): BooleanSets a scalar slot value. Returns true on success.
setTextSlot(slotId: String, text: String): BooleanSets a text slot value. Returns true on success.
setVectorSlot(slotId: String, vector: PointF): BooleanSets a vector slot value. Returns true on success.
setPositionSlot(slotId: String, position: PointF): BooleanSets a position slot value. Returns true on success.
setImageSlotPath(slotId: String, path: String): BooleanSets an image slot by file path. Returns true on success.
setImageSlotDataUrl(slotId: String, dataUrl: String): BooleanSets an image slot by data URL. Returns true on success.
setSlots(slots: String)Sets multiple slots at once from a JSON string.
clearSlot(slotId: String)Clears the value of a specific slot, resetting it to its default.
clearSlots()Clears all slot values, resetting them to their defaults.
stateMachineLoad(stateMachineId: String)Loads a state machine by its ID.
stateMachineLoadData(data: String): BooleanLoads a state machine from a raw JSON string.
stateMachineStart()Starts the loaded state machine.
stateMachineStop()Stops the active state machine.
stateMachineFireEvent(event: String)Fires a named event to the active state machine.
stateMachinePostEvent(event: Event)Posts a typed event to the active state machine.
stateMachineSetBooleanInput(key: String, value: Boolean)Sets a boolean input on the state machine.
stateMachineSetNumericInput(key: String, value: Float)Sets a numeric input on the state machine.
stateMachineSetStringInput(key: String, value: String)Sets a string input on the state machine.
stateMachineGetBooleanInput(key: String): Boolean?Gets the current value of a boolean state machine input.
stateMachineGetNumericInput(key: String): Float?Gets the current value of a numeric state machine input.
stateMachineGetStringInput(key: String): String?Gets the current value of a string state machine input.
stateMachineCurrentState(): String?Returns the name of the currently active state machine state.
stateMachineAddEventListener(listener: StateMachineEventListener)Adds a listener for state machine events.
stateMachineRemoveEventListener(listener: StateMachineEventListener)Removes a state machine event listener.
clearEventListeners()Removes all registered event listeners.

Events

The DotLottieAnimation class uses the DotLottieEventListener interface to notify about various animation events. Implementations of this interface can listen for the events defined in the DotLottieEventListener Interface section below (e.g., onPlay(), onPause(), onFrame(frame: Float), etc.).


DotLottieController Class

The DotLottieController class provides a comprehensive interface for managing the playback and configuration of dotLottie animations within Jetpack Compose.

Properties

PropertyDescriptionTypeAccess
isPlayingChecks if the animation is playing.StateFlow<Boolean>Read
isLoadedDetermines if the animation has been loaded successfully.StateFlow<Boolean>Read
isCompleteChecks if the animation has completed playing.StateFlow<Boolean>Read
isStoppedIndicates whether the animation is stopped.StateFlow<Boolean>Read
isPausedIndicates whether the animation is paused.StateFlow<Boolean>Read
speedThe playback speed of the animation.FloatRead
loopDetermines whether the animation should loop.BooleanRead
autoplayDetermines if the animation will start playing automatically.BooleanRead
totalFramesThe total number of frames in the animation.FloatRead
currentFrameThe current frame of the animation.StateFlow<Float>Read
playModeThe play mode of the animation (e.g., forward, reverse).ModeRead
segmentThe start and end frames of the current segment being played.Pair<Float, Float>?Read
durationThe duration of the animation in seconds.FloatRead
loopCountThe number of times the animation will loop.UIntRead
useFrameInterpolationChecks if frame interpolation is enabled for smoother animation.BooleanRead
activeThemeIdRetrieves the ID of the currently active theme.StateFlow<String>Read
activeAnimationIdRetrieves the ID of the currently active animation.StringRead
currentStateObservable player state flow.StateFlow<DotLottiePlayerState>Read
widthCurrent animation width.StateFlow<UInt>Read
heightCurrent animation height.StateFlow<UInt>Read
markersList of available markers.List<Marker>Read
stateMachineIsActiveWhether a state machine is currently running.BooleanRead

Methods

MethodDescriptionReturns
play()Starts or resumes the animation.void
pause()Pauses the animation.void
stop()Stops the animation and resets to the beginning.void
freeze()Freezes rendering.void
unFreeze()Resumes rendering.void
resize(width: UInt, height: UInt)Resizes the animation view.void
setFrame(frame: Float)Sets the current frame of the animation.void
setUseFrameInterpolation(enable: Boolean)Enables or disables frame interpolation.void
setSegment(firstFrame: Float, lastFrame: Float)Defines the start and end frames for a segment.void
setLoop(loop: Boolean)Sets whether the animation should loop.void
setSpeed(speed: Float)Sets the playback speed of the animation.void
setPlayMode(mode: Mode)Sets the play mode (e.g., forward, reverse, bounce).void
setLoopCount(loopCount: UInt)Sets the number of times the animation loops.void
setMarker(marker: String)Sets the animation to play from a named marker.void
setLayout(fit: Fit, alignment: Pair<Float, Float>)Sets the layout fit and alignment.void
setLayout(fit: Fit, alignment: LayoutUtil.Alignment)Sets the layout fit and alignment using the enum.void
loadAnimation(animationId: String)Loads a specific animation by ID from a multi-animation .lottie file.void
setTheme(themeId: String)Applies a theme by ID.void
setThemeData(themeData: String)Applies a theme from a raw JSON string.void
resetTheme()Resets the theme to the default theme.void
manifest(): Manifest?Retrieves the dotLottie manifest.Manifest?
setColorSlot(slotId: String, color: Int): BooleanSets a color slot value.Boolean
setScalarSlot(slotId: String, value: Float): BooleanSets a scalar slot value.Boolean
setTextSlot(slotId: String, text: String): BooleanSets a text slot value.Boolean
setVectorSlot(slotId: String, vector: PointF): BooleanSets a vector slot value.Boolean
setPositionSlot(slotId: String, position: PointF): BooleanSets a position slot value.Boolean
setImageSlotPath(slotId: String, path: String): BooleanSets an image slot by file path.Boolean
setImageSlotDataUrl(slotId: String, dataUrl: String): BooleanSets an image slot by data URL.Boolean
setSlots(slots: String)Sets multiple slots at once from a JSON string.void
clearSlot(slotId: String): BooleanClears a specific slot.Boolean
clearSlots(): BooleanClears all slots.Boolean
addEventListener(listener: DotLottieEventListener)Adds an event listener.void
removeEventListener(listener: DotLottieEventListener)Removes an event listener.void
clearEventListeners()Removes all registered event listeners.void
stateMachineLoad(stateMachineId: String)Loads a state machine by its ID.Boolean
stateMachineLoadData(data: String)Loads a state machine from a raw JSON string.Boolean
stateMachineStart(openUrl: OpenUrlPolicy, onOpenUrl: ((url: String) -> Unit)?)Starts the loaded state machine with URL policy.Boolean
stateMachineStop()Stops the active state machine.Boolean
stateMachineFire(event: String)Fires a named event to the active state machine.Boolean
stateMachinePostEvent(event: Event)Posts a typed event to the state machine.Boolean
stateMachinePostEvent(event: Event, force: Boolean)Posts an event with force option.Boolean
stateMachineSetBooleanInput(key: String, value: Boolean)Sets a boolean input.Boolean
stateMachineSetNumericInput(key: String, value: Float)Sets a numeric input.Boolean
stateMachineSetStringInput(key: String, value: String)Sets a string input.Boolean
stateMachineGetBooleanInput(key: String)Gets a boolean input value.Boolean?
stateMachineGetNumericInput(key: String)Gets a numeric input value.Float?
stateMachineGetStringInput(key: String)Gets a string input value.String?
stateMachineCurrentState()Returns the name of the currently active state.String?
stateMachineAddEventListener(listener: StateMachineEventListener)Adds a state machine event listener.void
stateMachineRemoveEventListener(listener: StateMachineEventListener)Removes a state machine event listener.void

Note: Both the Widget and the Controller expose freeze() / unFreeze(). The Widget implementation toggles the drawable's freeze flag directly; the Controller implementation calls pause() / play() and updates the playback state accordingly.


Event Handling

The DotLottieController class allows for the registration of event listeners that implement the DotLottieEventListener Interface interface. These listeners can respond to various animation events.

DotLottieEventListener Interface

The DotLottieEventListener interface defines a set of callback methods that respond to various animation events. Implementing this interface allows for handling animation lifecycle events, playback state changes, and rendering updates.

Methods

Event MethodDescription
onLoop(loopCount: Int)Called when the animation completes a loop. loopCount indicates the number of times the animation has looped.
onRender(frameNo: Float)Invoked for each frame rendered. frameNo is the current frame number.
onStop()Triggered when the animation stops.
onFrame(frame: Float)Called with the current frame number whenever the animation updates.
onPause()Invoked when the animation is paused.
onPlay()Triggered when the animation starts playing.
onComplete()Called when the animation completes all its loops and stops.
onLoad()Invoked when the animation is successfully loaded and ready to play.
onLoadError(error: Throwable)Called if there is an error loading the animation.
onError(error: Throwable)Called if there is a runtime error.
onFreeze()Triggered when the animation is frozen at the current frame.
onUnFreeze()Invoked when the animation resumes from a frozen state.
onDestroy()Called when the animation is destroyed and resources are released.

StateMachineEventListener Interface

The StateMachineEventListener interface defines callbacks for state machine events:

MethodDescription
onStart()Fired when the state machine starts.
onStop()Fired when the state machine stops.
onStateEntered(enteringState: String)Fired when entering a state.
onStateExit(leavingState: String)Fired when exiting a state.
onTransition(previousState: String, newState: String)Fired on a state transition.
onCustomEvent(message: String)Fired when a custom event is emitted.
onError(message: String)Fired when the state machine encounters an error.
onInputFired(inputName: String)Fired when an input fires.
onBooleanInputValueChange(inputName: String, oldValue: Boolean, newValue: Boolean)Fired when a boolean input changes.
onNumericInputValueChange(inputName: String, oldValue: Float, newValue: Float)Fired when a numeric input changes.
onStringInputValueChange(inputName: String, oldValue: String, newValue: String)Fired when a string input changes.

DotLottieSource

The DotLottieSource sealed class represents the different animation sources:

VariantConstructorDescription
UrlDotLottieSource.Url(url: String)Loads from a URL (.json or .lottie).
AssetDotLottieSource.Asset(path: String)Loads from the assets folder.
ResDotLottieSource.Res(resourceId: Int)Loads from Android res/raw resources.
DataDotLottieSource.Data(data: ByteArray)Loads from raw byte data (.lottie format).
JsonDotLottieSource.Json(jsonString: String)Loads from a Lottie JSON string.

Event Sealed Class (State Machine)

The Event sealed class represents events that can be posted to a state machine:

sealed class Event(val type: Int) {
    data class PointerDown(val x: Float, val y: Float) : Event(0)
    data class PointerUp(val x: Float, val y: Float) : Event(1)
    data class PointerMove(val x: Float, val y: Float) : Event(2)
    data class PointerEnter(val x: Float, val y: Float) : Event(3)
    data class PointerExit(val x: Float, val y: Float) : Event(4)
    data class Click(val x: Float, val y: Float) : Event(5)
    object OnComplete : Event(6)
    object OnLoopComplete : Event(7)
}

DotLottiePlayerState Enum

Represents the current state of the player:

ValueDescription
PLAYINGThe animation is currently playing.
PAUSEDThe animation is paused.
STOPPEDThe animation is stopped.
COMPLETEDThe animation has completed playback.
INITIALThe player is in its initial state.
LOADEDThe animation has been loaded.
ERRORAn error occurred.

Fit Enum

Controls how the animation scales within its container:

ValueDescription
CONTAINScale to fit within the container while maintaining aspect ratio (default).
COVERScale to cover the entire container while maintaining aspect ratio.
FILLStretch to fill the container, ignoring aspect ratio.
FIT_WIDTHScale to match the container's width, maintaining aspect ratio.
FIT_HEIGHTScale to match the container's height, maintaining aspect ratio.
NONENo scaling applied — renders at original size.

LayoutUtil.Alignment Enum

Predefined alignment positions for the animation within its container:

ValueDescription
TOP_LEFTAligns to the top-left corner.
TOP_CENTERAligns to the top center.
TOP_RIGHTAligns to the top-right corner.
CENTER_LEFTAligns to the center-left.
CENTERAligns to the center (default).
CENTER_RIGHTAligns to the center-right.
BOTTOM_LEFTAligns to the bottom-left corner.
BOTTOM_CENTERAligns to the bottom center.
BOTTOM_RIGHTAligns to the bottom-right corner.

Layout Data Class

The Layout data class configures the fit and alignment of the animation. Use createDefaultLayout() for the default configuration (Contain fit, centered alignment).


OpenUrlPolicy Data Class

Configures URL opening behavior for state machines:

PropertyTypeDescription
requireUserInteractionBooleanWhether user interaction is required before opening URLs.
whitelistList<String>List of allowed URL patterns.

Marker Data Class

Represents a named marker in the animation:

PropertyTypeDescription
nameStringThe marker name.
timeFloatThe time position of the marker.
durationFloatThe duration of the marker.

Manifest Data Class

Represents the dotLottie manifest from a .lottie file:

PropertyTypeDescription
activeAnimationIdString?The ID of the default active animation.
animationsList<Animation>List of animations in the file.
authorString?The author of the file.
descriptionString?Description of the file.
generatorString?The generator tool used.
keywordsString?Keywords associated with the file.
revisionInt?The revision number.
themesList<Theme>?List of available themes.
stateMachinesList<StateMachine>?List of available state machines.
versionString?The manifest version.
customDataMap<String, Any>?Custom metadata.

Manifest.Animation

PropertyTypeDescription
idStringThe animation ID.

Manifest.Theme

PropertyTypeDescription
idStringThe theme ID.

Manifest.StateMachine

PropertyTypeDescription
idStringThe state machine ID.

Config.Builder

The Config.Builder class constructs an animation configuration for loading with the Widget's load(config) method:

MethodDescription
.autoplay(value: Boolean)Sets autoplay behavior.
.loop(value: Boolean)Sets looping behavior.
.speed(value: Float)Sets playback speed.
.source(source: DotLottieSource)Sets the animation source.
.useFrameInterpolation(value: Boolean)Enables/disables frame interpolation.
.playMode(mode: Mode)Sets the play mode.
.layout(fit: Fit, alignment: Pair<Float, Float>)Sets layout fit and alignment.
.layout(fit: Fit, alignment: LayoutUtil.Alignment)Sets layout fit and alignment using the enum.
.themeId(themeId: String)Sets the theme to load.
.marker(marker: String)Sets the marker to play.
.animationId(animationId: String)Sets the animation ID for multi-animation files.
.stateMachineId(stateMachineId: String)Sets the state machine to load on init.
.threads(threads: UInt)Sets the number of rendering threads.
.loopCount(loopCount: UInt)Sets the maximum number of loop iterations.
.build()Builds the Config object.
val config = Config.Builder()
    .autoplay(true)
    .speed(1f)
    .loop(true)
    .source(DotLottieSource.Url("https://example.com/animation.lottie"))
    .useFrameInterpolation(true)
    .playMode(Mode.FORWARD)
    .build()
dotLottieAnimationView.load(config)
Last updated: April 10, 2026 at 9:12 AMEdit this page