rust_lum/src/audio.rs
2022-03-09 17:58:31 +01:00

19 lines
629 B
Rust

use rodio::{Decoder, OutputStream, Sink};
use std::fs::File;
use std::io::BufReader;
use std::path::Path;
pub fn play_sound(path: &Path) {
println!("starting musique");
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
let sink = Sink::try_new(&stream_handle).unwrap();
let file = BufReader::new(File::open(path).unwrap());
let source = Some(Decoder::new(file).unwrap()).unwrap();
sink.append(source);
// The sound plays in a separate thread. This call will block the current thread until the sink
// has finished playing all its queued sounds.
sink.sleep_until_end();
}