Play a file using rodio
This commit is contained in:
parent
516d50fe8b
commit
ac1d05089d
2 changed files with 15 additions and 0 deletions
|
@ -5,3 +5,4 @@ edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
rodio = "0.16.0"
|
||||||
|
|
14
src/main.rs
Normal file
14
src/main.rs
Normal 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");
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue