diff --git a/Cargo.lock b/Cargo.lock index 3e3d3346..b5900ee8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1491,14 +1491,10 @@ dependencies = [ ] [[package]] -name = "fancy-regex" -version = "0.11.0" +name = "extended" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b95f7c0680e4142284cf8b22c14a476e87d61b004a3a0861872b32ef7ead40a2" -dependencies = [ - "bit-set", - "regex", -] +checksum = "af9673d8203fcb076b19dfd17e38b3d4ae9f44959416ea532ce72415a6020365" [[package]] name = "fastrand" @@ -3133,6 +3129,14 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092" +[[package]] +name = "local_player" +version = "0.1.0" +dependencies = [ + "anyhow", + "rodio", +] + [[package]] name = "lock_api" version = "0.4.14" @@ -5055,6 +5059,7 @@ dependencies = [ "cpal", "dasp_sample", "num-rational", + "symphonia", ] [[package]] @@ -5849,12 +5854,28 @@ dependencies = [ "lazy_static", "symphonia-bundle-flac", "symphonia-bundle-mp3", + "symphonia-codec-aac", + "symphonia-codec-pcm", "symphonia-codec-vorbis", "symphonia-core", + "symphonia-format-isomp4", "symphonia-format-ogg", + "symphonia-format-riff", "symphonia-metadata", ] +[[package]] +name = "symphonia-bundle-flac" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72e34f34298a7308d4397a6c7fbf5b84c5d491231ce3dd379707ba673ab3bd97" +dependencies = [ + "log", + "symphonia-core", + "symphonia-metadata", + "symphonia-utils-xiph", +] + [[package]] name = "symphonia-bundle-flac" version = "0.5.5" @@ -5879,6 +5900,27 @@ dependencies = [ "symphonia-metadata", ] +[[package]] +name = "symphonia-codec-aac" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdbf25b545ad0d3ee3e891ea643ad115aff4ca92f6aec472086b957a58522f70" +dependencies = [ + "lazy_static", + "log", + "symphonia-core", +] + +[[package]] +name = "symphonia-codec-pcm" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f395a67057c2ebc5e84d7bb1be71cce1a7ba99f64e0f0f0e303a03f79116f89b" +dependencies = [ + "log", + "symphonia-core", +] + [[package]] name = "symphonia-codec-vorbis" version = "0.5.5" @@ -5903,6 +5945,19 @@ dependencies = [ "log", ] +[[package]] +name = "symphonia-format-isomp4" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abfdf178d697e50ce1e5d9b982ba1b94c47218e03ec35022d9f0e071a16dc844" +dependencies = [ + "encoding_rs", + "log", + "symphonia-core", + "symphonia-metadata", + "symphonia-utils-xiph", +] + [[package]] name = "symphonia-format-ogg" version = "0.5.5" @@ -5915,6 +5970,18 @@ dependencies = [ "symphonia-utils-xiph", ] +[[package]] +name = "symphonia-format-riff" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f7be232f962f937f4b7115cbe62c330929345434c834359425e043bfd15f50" +dependencies = [ + "extended", + "log", + "symphonia-core", + "symphonia-metadata", +] + [[package]] name = "symphonia-metadata" version = "0.5.5" diff --git a/Cargo.toml b/Cargo.toml index d656b22b..6a543c97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["spotify_player", "lyric_finder"] +members = ["spotify_player", "lyric_finder", "local_player"] resolver = "2" [profile.release] diff --git a/local_player/Cargo.toml b/local_player/Cargo.toml new file mode 100644 index 00000000..c17fcf07 --- /dev/null +++ b/local_player/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "local_player" +version = "0.1.0" +edition = "2024" + +[dependencies] +anyhow = "1.0.99" +rodio = "0.21.1" + +[lints] +workspace = true diff --git a/local_player/src/main.rs b/local_player/src/main.rs new file mode 100644 index 00000000..8fe5a0fa --- /dev/null +++ b/local_player/src/main.rs @@ -0,0 +1,36 @@ +use std::fs::File; +use rodio::{Decoder, OutputStream}; + +// Play music function. +// Sorry but they are from rodio's example, currently and I don't know if it works or not. I can't test it out. +// At least, VS Code tells me there 0 errors and 1 warnings (in this function) +// I'm new to Rust. +fn play_music(file: String) -> OutputStream { + // Define an stream handle and a sink. + let stream_handle = rodio::OutputStreamBuilder::open_default_stream() + .expect("opening default audio stream failed"); + let sink = rodio::Sink::connect_new(&stream_handle.mixer()); + // Load from a file + let file = File::open(file).unwrap(); + // Decode that sound file into a source + let source = Decoder::try_from(file).unwrap(); + // Play the sound directly on the device + stream_handle.mixer().add(source); + + // 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(5)); + + stream_handle +} + +fn main() -> anyhow::Result<()> { + println!( + "Hello from local_player member of spotify_player. The player is not implemented yet!" + ); + println!("Playing sound.mp3 from the current directory..."); + + play_music("sound.mp3".to_string()); + + Ok(()) +}