From 20461a452983a34c2db3622477b840ee33184051 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sat, 17 Dec 2022 23:48:49 -0800 Subject: [PATCH] feat: example mvp test --- src/main.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 111a36e..d13160f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,13 @@ +use rodio::{source::Source, Decoder, OutputStream}; +use std::fs::File; +use std::io::BufReader; use std::path::PathBuf; use clap::Parser; use dirs_next; +use crate::db_operations::{DatabaseRequest, PartialTag}; + pub mod db_operations; pub mod file_operations; @@ -47,7 +52,7 @@ fn main() { let music_scanner = file_operations::MusicScanner::new(music_dir); - let db_path: PathBuf = ["home", "nixolas", "RustedBeats.db"].iter().collect(); + let db_path: PathBuf = ["/", "home", "nixolas", "RustedBeats.db"].iter().collect(); let dbo = db_operations::DBObject::new(&db_path, false).unwrap(); @@ -62,5 +67,31 @@ fn main() { } } + let test_tag = PartialTag { + title: Some("Clap On, Clap Off".to_string()), + ..PartialTag::default() + }; + + let test_file = dbo + .get(&DatabaseRequest { + search_type: db_operations::SearchType::Where, + search_tag: test_tag, + }) + .unwrap() + .unwrap(); + + // Get a output stream handle to the default physical sound device + let (_stream, stream_handle) = OutputStream::try_default().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(); + // 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)); + println!("{:?}", cli); }