19 lines
629 B
Rust
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();
|
||
|
}
|