diff --git a/demo-player/src/main.rs b/demo-player/src/main.rs index deaf038b..b503a26d 100644 --- a/demo-player/src/main.rs +++ b/demo-player/src/main.rs @@ -128,17 +128,17 @@ fn main() { }); // read dotlottie in to vec - let mut f = File::open("src/cartoon.json").expect("no file found"); - let metadata = fs::metadata("src/cartoon.json").expect("unable to read metadata"); + let mut f = File::open("src/emoji.lottie").expect("no file found"); + let metadata = fs::metadata("src/emoji.lottie").expect("unable to read metadata"); let mut buffer = vec![0; metadata.len() as usize]; f.read(&mut buffer).expect("buffer overflow"); - let string = String::from_utf8(buffer.clone()).unwrap(); - lottie_player.load_animation_data(string.as_str(), WIDTH as u32, HEIGHT as u32); - println!("{:?}", Some(lottie_player.manifest())); + // let string = String::from_utf8(buffer.clone()).unwrap(); + // lottie_player.load_animation_data(string.as_str(), WIDTH as u32, HEIGHT as u32); + // println!("{:?}", Some(lottie_player.manifest())); - // lottie_player.load_dotlottie_data(&buffer, WIDTH as u32, HEIGHT as u32); + lottie_player.load_dotlottie_data(&buffer, WIDTH as u32, HEIGHT as u32); // lottie_player.load_animation("confused", WIDTH as u32, HEIGHT as u32); let observer1: Arc = Arc::new(DummyObserver { id: 1 }); @@ -149,6 +149,8 @@ fn main() { let mut timer = Timer::new(); + let mut i = 0; + let mut sys = System::new_all(); let cpu_memory_monitor_thread = thread::spawn(move || { @@ -195,6 +197,22 @@ fn main() { lottie_player.set_config(config) } + if window.is_key_down(Key::Right) { + if let Some(manifest) = lottie_player.manifest() { + println!("{:?}", i); + + if i >= manifest.animations.len() - 1 { + i = 0; + } else { + i += 1; + } + + let animation_id = manifest.animations[i].id.clone(); + + lottie_player.load_animation(animation_id.as_str(), WIDTH as u32, HEIGHT as u32); + } + } + if window.is_key_down(Key::Up) { lottie_player.unsubscribe(&observer1); } diff --git a/dotlottie-rs/src/lottie_renderer/mod.rs b/dotlottie-rs/src/lottie_renderer/mod.rs index ad14d99e..d16218d9 100644 --- a/dotlottie-rs/src/lottie_renderer/mod.rs +++ b/dotlottie-rs/src/lottie_renderer/mod.rs @@ -147,7 +147,7 @@ impl LottieRenderer { .map_err(LottieRendererError::ThorvgError)?; if let Some(picture) = &mut self.thorvg_picture { - picture.load_data(data.as_bytes(), "lottie", copy)?; + picture.load_data(data, "lottie", copy)?; let (pw, ph) = picture.get_size()?; let (scale, shift_x, shift_y) = calculate_scale_and_shift(pw, ph, width, height); diff --git a/dotlottie-rs/src/thorvg.rs b/dotlottie-rs/src/thorvg.rs index bcb35bbe..2a8c4168 100644 --- a/dotlottie-rs/src/thorvg.rs +++ b/dotlottie-rs/src/thorvg.rs @@ -173,14 +173,15 @@ impl Picture { convert_tvg_result(result, "tvg_picture_load") } - pub fn load_data(&mut self, data: &[u8], mimetype: &str, copy: bool) -> Result<(), TvgError> { + pub fn load_data(&mut self, data: &str, mimetype: &str, copy: bool) -> Result<(), TvgError> { let mimetype = CString::new(mimetype).expect("Failed to create CString"); + let data = CString::new(data).expect("Failed to create CString"); let result = unsafe { tvg_picture_load_data( self.raw_paint, - data.as_ptr() as *const std::ffi::c_char, - data.len() as u32, + data.as_ptr(), + data.as_bytes().len() as u32, mimetype.as_ptr(), copy, ) diff --git a/web-example.html b/web-example.html index 588ce357..d978a6ea 100644 --- a/web-example.html +++ b/web-example.html @@ -30,6 +30,7 @@ +