pub fn initialize() -> Result<()>Expand description
Initializes Libaudioverse. Failure to do so will result in crashes. You may initialize the library more than once: subsequent initializations do nothing.
Examples found in repository?
examples/file_playback.rs (line 7)
6fn main() {
7 libaudioverse::initialize().unwrap();
8
9 // server initialization
10 let server = Server::new().unwrap();
11 server.set_output_device().expect("Could not create default audio device");
12
13 // create a new buffer
14 let buf = Buffer::new(&server).unwrap();
15 let path = CString::new("test.ogg").unwrap();
16
17 // load audio data from test.ogg into this buffer
18 buf.load_from_file(&path).unwrap();
19
20 // create a Buffer node, associate it with the buffer just created, and play it
21 let buf_node = BufferNode::new(&server).unwrap();
22 buf_node.buffer().set(&buf).unwrap();
23 buf_node.connect_server(0).unwrap();
24
25 // wait for the whole file to finish playing
26 let duration = buf_node.position().get_range().unwrap().1.ceil() as u64;
27 thread::sleep(time::Duration::from_secs(duration));
28
29 libaudioverse::shutdown().unwrap();
30}