@@ -6,8 +6,7 @@ use std::sync::mpsc::channel;
6
6
use clap:: Parser ;
7
7
8
8
use rodio:: { source:: Source , Decoder , OutputStream } ;
9
- use std:: fs:: File ;
10
- use std:: io:: BufReader ;
9
+ use std:: io:: Cursor ;
11
10
12
11
/// Simple CLI meditation timer
13
12
#[ derive( Parser , Debug ) ]
@@ -19,14 +18,14 @@ struct Args {
19
18
}
20
19
21
20
const AUDIO_LENGTH_SECONDS : i64 = 26 ;
22
- const AUDIO_FILE_PATH : & str = "audio/bell.ogg" ;
23
21
24
22
fn main ( ) {
25
23
let args = Args :: parse ( ) ;
26
24
let timer = timer:: Timer :: new ( ) ;
27
25
let ( tx, rx) = channel ( ) ;
28
26
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 ) ;
30
29
31
30
invite ( ) ;
32
31
@@ -36,16 +35,14 @@ fn main() {
36
35
} ) ;
37
36
38
37
rx. recv ( ) . unwrap ( ) ;
39
- println ! (
40
- "{0} minute meditation complete 🧘♂️" ,
41
- args. minutes
42
- ) ;
38
+ println ! ( "{0} minute meditation complete 🧘♂️" , args. minutes) ;
43
39
}
44
40
45
41
fn invite ( ) {
42
+ let bytes = include_bytes ! ( "../audio/bell.ogg" ) ;
46
43
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 ( ) ;
49
46
let _ = stream_handle. play_raw ( source. convert_samples ( ) ) ;
50
47
51
48
std:: thread:: sleep ( std:: time:: Duration :: from_secs ( AUDIO_LENGTH_SECONDS as u64 ) ) ;
0 commit comments