chore: assign name to audio thread
This commit is contained in:
parent
72cf545e79
commit
45df95704d
26
src/alert.rs
26
src/alert.rs
|
@ -2,6 +2,7 @@ use rodio::{Decoder, OutputStream, Sink};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Alert {
|
pub struct Alert {
|
||||||
|
@ -20,20 +21,21 @@ impl Alert {
|
||||||
pub fn play(&self) {
|
pub fn play(&self) {
|
||||||
let file = File::open(&self.path).unwrap();
|
let file = File::open(&self.path).unwrap();
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
thread::Builder::new()
|
||||||
let (_stream, handle) = OutputStream::try_default().unwrap();
|
.name("Audio Thread".to_string())
|
||||||
let source = Decoder::new(BufReader::new(file)).unwrap();
|
.spawn(move || {
|
||||||
let sink = Sink::try_new(&handle).unwrap();
|
let (_stream, handle) = OutputStream::try_default().unwrap();
|
||||||
|
let source = Decoder::new(BufReader::new(file)).unwrap();
|
||||||
|
let sink = Sink::try_new(&handle).unwrap();
|
||||||
|
|
||||||
sink.append(source);
|
sink.append(source);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if sink.len() == 0 {
|
if sink.len() == 0 {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
.unwrap();
|
||||||
println!("Exited Playback Thread.");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue