1use motion_canvas_rs::prelude::*;
2use std::time::Duration;
3
4fn main() {
5 let mut project = Project::default()
6 .with_dimensions(800, 450)
7 .with_title("Audio Demo")
8 .with_background(Color::rgb8(20, 20, 25))
9 .close_on_finish();
10
11 let rect = Rect::new(Vec2::new(100.0, 100.0), Vec2::new(200.0, 200.0), Color::RED)
13 .with_anchor(Vec2::new(-1.0, -1.0));
14
15 project.scene.add(&rect);
16
17 project.scene.video_timeline.add(chain!(
18 all![
19 rect.position
20 .to(Vec2::new(150.0, 150.0), Duration::from_secs(1)),
21 rect.size.to(Vec2::new(200.0, 50.0), Duration::from_secs(1)),
22 rect.fill_paint
23 .to(Paint::Solid(Color::BLUE), Duration::from_secs(1)),
24 ],
25 all![
26 rect.position
27 .to(Vec2::new(350.0, 150.0), Duration::from_secs(1)),
28 rect.fill_paint
29 .to(Paint::Solid(Color::RED), Duration::from_secs(1)),
30 ]
31 ));
32
33 project.scene.audio_timeline.add(chain!(
35 play!(AudioNode::new("./examples/audios/combo-1.mp3").with_volume(0.5)),
36 audio_wait!(0.05),
37 play!(AudioNode::new("./examples/audios/combo-2.mp3").with_volume(1.0))
38 ));
39
40 println!("Project configured with separate video and audio timelines.");
41 println!(
42 "Video duration: {:?}",
43 project.scene.video_timeline.duration()
44 );
45 println!(
46 "Audio duration: {:?}",
47 project.scene.audio_timeline.duration()
48 );
49
50 project.show().expect("Failed to run audio demo");
51}