Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions dotlottie-rs/examples/audio_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#![allow(clippy::print_stdout)]

use dotlottie_rs::{ColorSpace, DotLottieEvent, DotLottiePlayer};
use dotlottie_rs::{ColorSpace, DotLottieEvent, DotLottiePlayer, Status};
use minifb::{Key, Window, WindowOptions};
use std::ffi::CString;
use std::fs;
Expand Down Expand Up @@ -134,13 +134,13 @@ fn main() {
let plus_down = window.is_key_down(Key::Equal) || window.is_key_down(Key::NumPadPlus);
let minus_down = window.is_key_down(Key::Minus) || window.is_key_down(Key::NumPadMinus);

if p_was_down && !p_down && (player.is_paused() || player.is_stopped()) {
if p_was_down && !p_down && player.status() != Status::Playing {
let _ = player.play();
}
if s_was_down && !s_down && player.is_playing() {
if s_was_down && !s_down && player.status() == Status::Playing {
let _ = player.pause();
}
if x_was_down && !x_down && !player.is_stopped() {
if x_was_down && !x_down && player.status() != Status::Stopped {
let _ = player.stop();
}

Expand Down Expand Up @@ -182,12 +182,11 @@ fn main() {
} else {
""
};
let state = if player.is_playing() {
"PLAYING"
} else if player.is_paused() {
"PAUSED "
} else {
"STOPPED"
let state = match player.status() {
Status::Idle => "IDLE",
Status::Playing => "PLAYING",
Status::Paused => "PAUSED",
Status::Stopped => "STOPPED",
};
let frame = player.current_frame();
let vol = player.audio_volume();
Expand All @@ -202,7 +201,7 @@ fn main() {
while let Some(event) = player.poll_event() {
let _ = player.current_frame();
match event {
DotLottieEvent::Load => println!(" -- Load (is_loaded={})", player.is_loaded()),
DotLottieEvent::Load => println!(" -- Load (status={:?})", player.status()),
DotLottieEvent::LoadError => {
eprintln!(" !! LoadError — animation failed to load into ThorVG");
}
Expand Down
37 changes: 6 additions & 31 deletions dotlottie-rs/src/c_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::lottie_renderer::{
ColorSlot, ColorValue, GlContext, GlDisplay, GlSurface, ImageSlot, PositionSlot, ScalarSlot,
ScalarValue, TextDocument, TextSlot, VectorSlot, WgpuDevice, WgpuInstance, WgpuTarget,
};
use crate::{DotLottiePlayer, DotLottiePlayerError, Layout, Mode, Rgba, Segment};
use crate::{DotLottiePlayer, DotLottiePlayerError, Layout, Mode, Rgba, Segment, Status};

use crate::ColorSpace;

Expand Down Expand Up @@ -716,38 +716,13 @@ pub unsafe extern "C" fn dotlottie_current_loop_count(
})
}

/// Returns whether an animation is loaded.
/// Returns the current status (Idle, Playing, Paused, or Stopped).
/// Returns Idle if the pointer is invalid.
#[no_mangle]
pub unsafe extern "C" fn dotlottie_is_loaded(ptr: *mut DotLottiePlayer) -> bool {
pub unsafe extern "C" fn dotlottie_status(ptr: *mut DotLottiePlayer) -> Status {
match ptr.as_mut() {
Some(p) => p.is_loaded(),
_ => false,
}
}

/// Returns the current playback status.
///
/// Priority order: Playing > Paused > Stopped
///
/// # Parameters
/// - `ptr`: Pointer to the DotLottiePlayer instance
///
/// # Returns
/// The current PlaybackStatus (Playing, Paused, or Stopped)
/// Returns Stopped if the pointer is invalid
#[no_mangle]
pub unsafe extern "C" fn dotlottie_playback_status(ptr: *mut DotLottiePlayer) -> PlaybackStatus {
match ptr.as_mut() {
Some(p) => {
if p.is_playing() {
PlaybackStatus::Playing
} else if p.is_paused() {
PlaybackStatus::Paused
} else {
PlaybackStatus::Stopped
}
}
_ => PlaybackStatus::Stopped,
Some(p) => p.status(),
_ => Status::Idle,
}
}

Expand Down
8 changes: 0 additions & 8 deletions dotlottie-rs/src/c_api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ use core::str::FromStr;
use crate::lottie_renderer::LottieRendererError;
use crate::DotLottiePlayerError;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub enum PlaybackStatus {
Playing = 0,
Paused = 1,
Stopped = 2,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub enum DotLottieResult {
Expand Down
Loading
Loading