Skip to content

Commit 06bcf84

Browse files
committed
encode file
1 parent 47abd7e commit 06bcf84

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/main.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use std::sync::mpsc::channel;
66
use clap::Parser;
77

88
use rodio::{source::Source, Decoder, OutputStream};
9-
use std::fs::File;
10-
use std::io::BufReader;
9+
use std::io::Cursor;
1110

1211
/// Simple CLI meditation timer
1312
#[derive(Parser, Debug)]
@@ -19,14 +18,14 @@ struct Args {
1918
}
2019

2120
const AUDIO_LENGTH_SECONDS: i64 = 26;
22-
const AUDIO_FILE_PATH: &str = "audio/bell.ogg";
2321

2422
fn main() {
2523
let args = Args::parse();
2624
let timer = timer::Timer::new();
2725
let (tx, rx) = channel();
2826

29-
let delay = chrono::Duration::minutes(args.minutes) - chrono::Duration::seconds(AUDIO_LENGTH_SECONDS);
27+
let delay =
28+
chrono::Duration::minutes(args.minutes) - chrono::Duration::seconds(AUDIO_LENGTH_SECONDS);
3029

3130
invite();
3231

@@ -36,16 +35,14 @@ fn main() {
3635
});
3736

3837
rx.recv().unwrap();
39-
println!(
40-
"{0} minute meditation complete 🧘‍♂️",
41-
args.minutes
42-
);
38+
println!("{0} minute meditation complete 🧘‍♂️", args.minutes);
4339
}
4440

4541
fn invite() {
42+
let bytes = include_bytes!("../audio/bell.ogg");
4643
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
47-
let file = BufReader::new(File::open(AUDIO_FILE_PATH).unwrap());
48-
let source = Decoder::new(file).unwrap();
44+
let cursor = Cursor::new(&bytes[..]);
45+
let source = Decoder::new(cursor).unwrap();
4946
let _ = stream_handle.play_raw(source.convert_samples());
5047

5148
std::thread::sleep(std::time::Duration::from_secs(AUDIO_LENGTH_SECONDS as u64));

0 commit comments

Comments
 (0)