pub fn start(rx_alarm_runner: mpsc::Receiver<Message>) -> JoinHandle<()> {
    let join_handle = thread::spawn(move || {

        let device = rodio::default_output_device().unwrap();
        let mut sink = Sink::new(&device);

        loop {
            match rx_alarm_runner.recv() {
                Ok(Message::AudioAndVolume(a_file_path, a_volume)) => {
                    let file = File::open(a_file_path).unwrap();
                    let source = rodio::Decoder::new(BufReader::new(file)).unwrap();
                    sink = Sink::new(&device);
                    sink.append(source);
                    sink.set_volume(to_volume(a_volume));
                    sink.play(); // should already be ok
                },
                Ok(Message::StopAlarm) => {
                    sink.stop()
                },
                _ => {
                    sink.stop();
                    break;
                }
            };
        }
    });

    join_handle
}
/// Runs a thread that manages the audio file
Runs a thread that manages the audio file
Runs a thread that manages the audio file
pub fn start(rx_alarm_runner: mpsc::Receiver<Message>) -> JoinHandle<()> {
    let join_handle = thread::spawn(move || {
        let device = rodio::default_output_device().unwrap();
        let mut sink = Sink::new(&device);
        loop {
            match rx_alarm_runner.recv() {
                Ok(Message::AudioAndVolume(a_file_path, a_volume)) => {
                    let file = File::open(a_file_path).unwrap();
                    let source = rodio::Decoder::new(BufReader::new(file)).unwrap();
                    sink = Sink::new(&device);
                    sink.append(source);
                    sink.set_volume(to_volume(a_volume));
                    sink.play(); // should already be ok
                },
                Ok(Message::StopAlarm) => {
                    sink.stop()
                },
                _ => {
                    sink.stop();
                    break;
                }
            };
        }
    });
    join_handle
}
pub fn start ( rx_alarm_runner : mpsc :: Receiver < Message > ) -> JoinHandle < ( ) > { let join_handle = thread :: spawn ( move | | { let device = rodio :: default_output_device ( ) . unwrap ( ) ; let mut sink = Sink :: new ( & device ) ; loop { match rx_alarm_runner . recv ( ) { Ok ( Message :: AudioAndVolume ( a_file_path , a_volume ) ) => { let file = File :: open ( a_file_path ) . unwrap ( ) ; let source = rodio :: Decoder :: new ( BufReader :: new ( file ) ) . unwrap ( ) ; sink = Sink :: new ( & device ) ; sink . append ( source ) ; sink . set_volume ( to_volume ( a_volume ) ) ; sink . play ( ) ; // should already be ok } , Ok ( Message :: StopAlarm ) => { sink . stop ( ) } , _ => { sink . stop ( ) ; break ; } } ; } } ) ; join_handle }
Runs a thread that manages the audio file
Runs a thread that manages the audio file
rx_alarm_runner
mpsc::Receiver<Message>
rx_alarm_runner
mpsc::Receiver<Message>