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
| Parameter | Description | Type | Default Value |
modifier | The modifier to be applied to the animation view. | Modifier | Modifier |
source* | The URL source of the animation. | DotLottieSource | null |
autoplay | Determines if the animation will start playing automatically. | Boolean | false |
loop | Determines whether the animation should loop. | Boolean | false |
loopCount | Maximum number of loop iterations (0 = infinite). | UInt | 0u |
useFrameInterpolation | Enables or disables frame interpolation for smoother animation. | Boolean | true |
themeId | The themeId to be loaded. | String | null |
marker | The segment name or marker to be played. | String | null |
speed | The playback speed of the animation. | Float | 1f |
segment | The segment to be played. | Pair<Float, Float> | null |
playMode | The play mode of the animation (e.g., forward, reverse). | Mode | Mode.FORWARD |
controller | The controller for managing animation playback and state. | DotLottieController | null |
layout | Sets the the layout of the Animation. | Layout | createDefaultLayout() |
eventListeners | A list of event listeners for animation events. | List<DotLottieEventListener> | emptyList() |
stateMachineId | The ID of a state machine to load automatically on init. | String? | null |
threads | Number of rendering threads. | UInt? | null |
Functionality
Loading Animations: The
DotLottieAnimationcomposable function supports loading animations from various sources, including URLs, asset files, raw resources, or raw data using theDotLottieSourcetype. At least one source must be provided (either via thesourceparameter or thecontroller).Playback Control: The function integrates with
DotLottieControllerfor controlling animation playback, including play, pause, and stop functionalities. Theautoplayandloopparameters provide initial playback behavior.Customization: Parameters such as
speed,playMode,useFrameInterpolation,marker, andsegmentallow for customization of the animation playback, including its speed, direction, smoothness, and specific parts to play.Event Handling: The
eventListenersparameter allows developers to attach multiple event listeners to handle various animation events, such as loading errors or completion, using theDotLottieEventListenerinterface.Theming: The
themeIdparameter allows applying pre-defined themes packed within a.lottiefile.Layout: The
layoutparameter controls how the animation fits and aligns within the composable's bounds.State Machine: The
stateMachineIdparameter 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 Attribute | Description | Format | Default Value |
dotLottie_src | Specifies the source of the Lottie animation. This can be a local asset filename or a URL to a .lottie or .json file. | string | None |
dotLottie_loop | Determines whether the animation should loop indefinitely. | boolean | false |
dotLottie_playMode | Defines the play mode of the animation when it reaches the end and the repeat count is greater than 0 or infinite. | enum | normal (1) |
dotLottie_speed | Adjusts 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. | float | 1.0f |
dotLottie_autoplay | Determines if the animation will start playing automatically upon loading. | boolean | false |
dotLottie_backgroundColor | Sets the background color of the animation view. | integer | None |
dotLottie_useFrameInterpolation | Enables or disables frame interpolation for smoother animation playback. | boolean | true |
dotLottie_themeId | Sets the themeId to load. | string | "" |
dotLottie_stateMachineId | Sets the state machine ID to load on initialization. | string | "" |
dotLottie_marker | Sets the marker to play. | string | "" |
dotLottie_animationId | Sets 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
| Property | Description | Type | Access |
speed | Gets the playback speed of the animation. | Float | Read |
loop | Checks if the animation is set to loop. | Boolean | Read |
autoplay | Determines if the animation will start playing automatically. | Boolean | Read |
isPlaying | Indicates whether the animation is currently playing. | Boolean | Read |
isPaused | Indicates whether the animation is paused. | Boolean | Read |
isStopped | Indicates whether the animation is stopped. | Boolean | Read |
isLoaded | Checks if the animation has been loaded successfully. | Boolean | Read |
totalFrames | Gets the total number of frames in the animation. | Float | Read |
currentFrame | Gets the current frame of the animation. | Float | Read |
playMode | Gets the current play mode of the animation. | Mode | Read |
segment | Gets the start and end frames of the current segment being played. | Pair<Float, Float> | Read |
duration | Gets the duration of the animation in seconds. | Float | Read |
loopCount | Gets the number of times the animation will loop. | UInt | Read |
useFrameInterpolation | Checks if frame interpolation is enabled for smoother animation. | Boolean | Read |
marker | Gets the current marker of the animation. | String | Read |
markers | Gets the list of markers in the animation. | List<Marker> | Read |
activeThemeId | Retrieves the ID of the currently active theme. | String | Read |
activeAnimationId | Retrieves the ID of the currently active animation. | String | Read |
Methods
| Method | Description |
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): Boolean | Sets a color slot value. Returns true on success. |
setScalarSlot(slotId: String, value: Float): Boolean | Sets a scalar slot value. Returns true on success. |
setTextSlot(slotId: String, text: String): Boolean | Sets a text slot value. Returns true on success. |
setVectorSlot(slotId: String, vector: PointF): Boolean | Sets a vector slot value. Returns true on success. |
setPositionSlot(slotId: String, position: PointF): Boolean | Sets a position slot value. Returns true on success. |
setImageSlotPath(slotId: String, path: String): Boolean | Sets an image slot by file path. Returns true on success. |
setImageSlotDataUrl(slotId: String, dataUrl: String): Boolean | Sets 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): Boolean | Loads 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
| Property | Description | Type | Access |
isPlaying | Checks if the animation is playing. | StateFlow<Boolean> | Read |
isLoaded | Determines if the animation has been loaded successfully. | StateFlow<Boolean> | Read |
isComplete | Checks if the animation has completed playing. | StateFlow<Boolean> | Read |
isStopped | Indicates whether the animation is stopped. | StateFlow<Boolean> | Read |
isPaused | Indicates whether the animation is paused. | StateFlow<Boolean> | Read |
speed | The playback speed of the animation. | Float | Read |
loop | Determines whether the animation should loop. | Boolean | Read |
autoplay | Determines if the animation will start playing automatically. | Boolean | Read |
totalFrames | The total number of frames in the animation. | Float | Read |
currentFrame | The current frame of the animation. | StateFlow<Float> | Read |
playMode | The play mode of the animation (e.g., forward, reverse). | Mode | Read |
segment | The start and end frames of the current segment being played. | Pair<Float, Float>? | Read |
duration | The duration of the animation in seconds. | Float | Read |
loopCount | The number of times the animation will loop. | UInt | Read |
useFrameInterpolation | Checks if frame interpolation is enabled for smoother animation. | Boolean | Read |
activeThemeId | Retrieves the ID of the currently active theme. | StateFlow<String> | Read |
activeAnimationId | Retrieves the ID of the currently active animation. | String | Read |
currentState | Observable player state flow. | StateFlow<DotLottiePlayerState> | Read |
width | Current animation width. | StateFlow<UInt> | Read |
height | Current animation height. | StateFlow<UInt> | Read |
markers | List of available markers. | List<Marker> | Read |
stateMachineIsActive | Whether a state machine is currently running. | Boolean | Read |
Methods
| Method | Description | Returns |
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): Boolean | Sets a color slot value. | Boolean |
setScalarSlot(slotId: String, value: Float): Boolean | Sets a scalar slot value. | Boolean |
setTextSlot(slotId: String, text: String): Boolean | Sets a text slot value. | Boolean |
setVectorSlot(slotId: String, vector: PointF): Boolean | Sets a vector slot value. | Boolean |
setPositionSlot(slotId: String, position: PointF): Boolean | Sets a position slot value. | Boolean |
setImageSlotPath(slotId: String, path: String): Boolean | Sets an image slot by file path. | Boolean |
setImageSlotDataUrl(slotId: String, dataUrl: String): Boolean | Sets an image slot by data URL. | Boolean |
setSlots(slots: String) | Sets multiple slots at once from a JSON string. | void |
clearSlot(slotId: String): Boolean | Clears a specific slot. | Boolean |
clearSlots(): Boolean | Clears 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 callspause()/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 Method | Description |
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:
| Method | Description |
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:
| Variant | Constructor | Description |
Url | DotLottieSource.Url(url: String) | Loads from a URL (.json or .lottie). |
Asset | DotLottieSource.Asset(path: String) | Loads from the assets folder. |
Res | DotLottieSource.Res(resourceId: Int) | Loads from Android res/raw resources. |
Data | DotLottieSource.Data(data: ByteArray) | Loads from raw byte data (.lottie format). |
Json | DotLottieSource.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:
| Value | Description |
PLAYING | The animation is currently playing. |
PAUSED | The animation is paused. |
STOPPED | The animation is stopped. |
COMPLETED | The animation has completed playback. |
INITIAL | The player is in its initial state. |
LOADED | The animation has been loaded. |
ERROR | An error occurred. |
Fit Enum
Controls how the animation scales within its container:
| Value | Description |
CONTAIN | Scale to fit within the container while maintaining aspect ratio (default). |
COVER | Scale to cover the entire container while maintaining aspect ratio. |
FILL | Stretch to fill the container, ignoring aspect ratio. |
FIT_WIDTH | Scale to match the container's width, maintaining aspect ratio. |
FIT_HEIGHT | Scale to match the container's height, maintaining aspect ratio. |
NONE | No scaling applied — renders at original size. |
LayoutUtil.Alignment Enum
Predefined alignment positions for the animation within its container:
| Value | Description |
TOP_LEFT | Aligns to the top-left corner. |
TOP_CENTER | Aligns to the top center. |
TOP_RIGHT | Aligns to the top-right corner. |
CENTER_LEFT | Aligns to the center-left. |
CENTER | Aligns to the center (default). |
CENTER_RIGHT | Aligns to the center-right. |
BOTTOM_LEFT | Aligns to the bottom-left corner. |
BOTTOM_CENTER | Aligns to the bottom center. |
BOTTOM_RIGHT | Aligns 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:
| Property | Type | Description |
requireUserInteraction | Boolean | Whether user interaction is required before opening URLs. |
whitelist | List<String> | List of allowed URL patterns. |
Marker Data Class
Represents a named marker in the animation:
| Property | Type | Description |
name | String | The marker name. |
time | Float | The time position of the marker. |
duration | Float | The duration of the marker. |
Manifest Data Class
Represents the dotLottie manifest from a .lottie file:
| Property | Type | Description |
activeAnimationId | String? | The ID of the default active animation. |
animations | List<Animation> | List of animations in the file. |
author | String? | The author of the file. |
description | String? | Description of the file. |
generator | String? | The generator tool used. |
keywords | String? | Keywords associated with the file. |
revision | Int? | The revision number. |
themes | List<Theme>? | List of available themes. |
stateMachines | List<StateMachine>? | List of available state machines. |
version | String? | The manifest version. |
customData | Map<String, Any>? | Custom metadata. |
Manifest.Animation
| Property | Type | Description |
id | String | The animation ID. |
Manifest.Theme
| Property | Type | Description |
id | String | The theme ID. |
Manifest.StateMachine
| Property | Type | Description |
id | String | The state machine ID. |
Config.Builder
The Config.Builder class constructs an animation configuration for loading with the Widget's load(config) method:
| Method | Description |
.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)