File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #![ allow( clippy:: needless_return) ]
2+ //! Audio demo exercising `AudioContext` transport controls.
3+ //!
4+ //! This demo validates that `AudioContext` can play a decoded `SoundBuffer`
5+ //! through the output device and that `SoundInstance` transport operations
6+ //! (play/pause/stop/looping) behave as expected.
7+
8+ use std:: time:: Duration ;
9+
10+ use lambda:: audio:: {
11+ AudioContextBuilder ,
12+ SoundBuffer ,
13+ } ;
14+
15+ fn main ( ) {
16+ const SLASH_VORBIS_STEREO_48000_OGG : & [ u8 ] = include_bytes ! ( concat!(
17+ env!( "CARGO_MANIFEST_DIR" ) ,
18+ "/../../crates/lambda-rs-platform/assets/audio/slash_vorbis_stereo_48000.ogg"
19+ ) ) ;
20+
21+ let buffer =
22+ SoundBuffer :: from_ogg_bytes ( SLASH_VORBIS_STEREO_48000_OGG ) . unwrap ( ) ;
23+
24+ let mut context = AudioContextBuilder :: new ( )
25+ . with_label ( "sound-playback-transport" )
26+ . with_sample_rate ( buffer. sample_rate ( ) )
27+ . with_channels ( buffer. channels ( ) )
28+ . build ( )
29+ . unwrap ( ) ;
30+
31+ let mut instance = context. play_sound ( & buffer) . unwrap ( ) ;
32+ std:: thread:: sleep ( Duration :: from_millis ( 250 ) ) ;
33+
34+ instance. pause ( ) ;
35+ std:: thread:: sleep ( Duration :: from_millis ( 250 ) ) ;
36+
37+ instance. play ( ) ;
38+ std:: thread:: sleep ( Duration :: from_millis ( 250 ) ) ;
39+
40+ instance. stop ( ) ;
41+ std:: thread:: sleep ( Duration :: from_millis ( 250 ) ) ;
42+
43+ instance. play ( ) ;
44+ std:: thread:: sleep ( Duration :: from_millis ( 300 ) ) ;
45+
46+ instance. set_looping ( true ) ;
47+ std:: thread:: sleep ( Duration :: from_secs ( 2 ) ) ;
48+
49+ instance. set_looping ( false ) ;
50+ std:: thread:: sleep ( Duration :: from_millis ( 300 ) ) ;
51+ return ;
52+ }
You can’t perform that action at this time.
0 commit comments