Play a file using rodio

This commit is contained in:
George Kaklamanos 2022-10-22 21:01:09 +03:00
parent 516d50fe8b
commit ac1d05089d
2 changed files with 15 additions and 0 deletions

View file

@ -5,3 +5,4 @@ edition = "2021"
license = "GPL-3.0-or-later"
[dependencies]
rodio = "0.16.0"

14
src/main.rs Normal file
View file

@ -0,0 +1,14 @@
fn play_file(file: &str) {
use rodio::{Decoder, OutputStream, source::Source};
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
let file = std::io::BufReader::new(std::fs::File::open(file).unwrap());
let source = Decoder::new(file).unwrap();
stream_handle.play_raw(source.convert_samples()).unwrap();
std::thread::sleep(std::time::Duration::from_secs(5));
}
fn main() {
play_file("test.flac");
}