From 589fa62e73ab18ffaa5be47d5db62a1d5cdf1e63 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sun, 18 Dec 2022 13:57:53 -0800 Subject: [PATCH] test: changed to sinks and fuzzy search --- src/main.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index d13160f..af371a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use rodio::{source::Source, Decoder, OutputStream}; +use rodio::{source::Source, Decoder, OutputStream, Sink}; use std::fs::File; use std::io::BufReader; use std::path::PathBuf; @@ -68,13 +68,13 @@ fn main() { } let test_tag = PartialTag { - title: Some("Clap On, Clap Off".to_string()), + title: Some("%bees%".to_string()), ..PartialTag::default() }; let test_file = dbo .get(&DatabaseRequest { - search_type: db_operations::SearchType::Where, + search_type: db_operations::SearchType::Like, search_tag: test_tag, }) .unwrap() @@ -82,16 +82,19 @@ fn main() { // Get a output stream handle to the default physical sound device let (_stream, stream_handle) = OutputStream::try_default().unwrap(); + // open an audio sink + let sink = Sink::try_new(&stream_handle).unwrap(); // Load a sound from a file, using a path relative to Cargo.toml let file = BufReader::new(File::open(test_file[0].path.clone()).unwrap()); // Decode that sound file into a source let source = Decoder::new(file).unwrap(); + sink.append(source); // Play the sound directly on the device - stream_handle.play_raw(source.convert_samples()).unwrap(); - - // The sound plays in a separate audio thread, - // so we need to keep the main thread alive while it's playing. - std::thread::sleep(std::time::Duration::from_secs(35)); + std::thread::sleep(std::time::Duration::from_secs(5)); + sink.pause(); + std::thread::sleep(std::time::Duration::from_secs(5)); + sink.play(); + sink.sleep_until_end(); println!("{:?}", cli); }