Check for existing annotations
This commit is contained in:
parent
c4c509c1e1
commit
b6db840208
1 changed files with 22 additions and 13 deletions
35
src/main.rs
35
src/main.rs
|
@ -200,6 +200,7 @@ fn main() {
|
|||
|
||||
let sample_rate: Arc<FairMutex<usize>> = Arc::new(FairMutex::new(44100));
|
||||
|
||||
// The audio output stream / thread
|
||||
let stream = {
|
||||
let idx = Arc::clone(&idx);
|
||||
let buf = Arc::clone(&buf);
|
||||
|
@ -305,27 +306,35 @@ fn main() {
|
|||
|
||||
let file = File::open(path.as_ref().unwrap()).unwrap();
|
||||
|
||||
let mut mp3dec = Decoder::new(file);
|
||||
|
||||
// If there are no annotations for the file, load it and begin the process of annotating;
|
||||
if xattr::get(path.as_ref().unwrap(), "user.ad-annotation")
|
||||
.unwrap()
|
||||
.is_none()
|
||||
{
|
||||
buf.lock().clear();
|
||||
let mut mp3dec = Decoder::new(file);
|
||||
|
||||
let mut is_first = true;
|
||||
{
|
||||
buf.lock().clear();
|
||||
|
||||
while let Ok(frame) = mp3dec.next_frame() {
|
||||
buf.lock().extend_from_slice(&frame.data);
|
||||
let mut is_first = true;
|
||||
|
||||
// Get settings only from the first frame
|
||||
if is_first {
|
||||
is_first = false;
|
||||
while let Ok(frame) = mp3dec.next_frame() {
|
||||
buf.lock().extend_from_slice(&frame.data);
|
||||
|
||||
let mut mp3_channels = mp3_channels.lock();
|
||||
*mp3_channels = Some(frame.channels);
|
||||
// Get settings only from the first frame
|
||||
if is_first {
|
||||
is_first = false;
|
||||
|
||||
let mut sample_rate = sample_rate.lock();
|
||||
*sample_rate = frame.sample_rate as usize;
|
||||
let mut mp3_channels = mp3_channels.lock();
|
||||
*mp3_channels = Some(frame.channels);
|
||||
|
||||
let mut sample_rate = sample_rate.lock();
|
||||
*sample_rate = frame.sample_rate as usize;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
execute!(stdout, MoveToNextLine(1), MoveToColumn(0), Print("\t🗃 Annotations Found")).unwrap();
|
||||
}
|
||||
} // while buf empty
|
||||
|
||||
|
|
Loading…
Reference in a new issue