From 6724bfd398d1c4532553614f9b6029af3f3a97fb Mon Sep 17 00:00:00 2001 From: Mani Arasteh Date: Thu, 18 Sep 2025 12:46:19 +0330 Subject: [PATCH 1/3] Add `local_player` as a member for local playback --- Cargo.lock | 4 ++++ Cargo.toml | 2 +- local_player/Cargo.toml | 9 +++++++++ local_player/src/main.rs | 3 +++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 local_player/Cargo.toml create mode 100644 local_player/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index c25fa5ea..c06bc2d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2826,6 +2826,10 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f5e54036fe321fd421e10d732f155734c4e4afd610dd556d9a82833ab3ee0bed" +[[package]] +name = "local_player" +version = "0.1.0" + [[package]] name = "lock_api" version = "0.4.13" 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..bd39b788 --- /dev/null +++ b/local_player/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "local_player" +version = "0.1.0" +edition = "2024" + +[dependencies] + +[lints] +workspace = true diff --git a/local_player/src/main.rs b/local_player/src/main.rs new file mode 100644 index 00000000..979f43ea --- /dev/null +++ b/local_player/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello from local_player member of spotify_player. The player is not implemented yet!"); +} From 02eae1a8d97b4328329ffc971789ae5b54a6fc73 Mon Sep 17 00:00:00 2001 From: Mani Arasteh Date: Thu, 18 Sep 2025 12:53:05 +0330 Subject: [PATCH 2/3] Fixed the formatting, not important by the way. --- local_player/src/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/local_player/src/main.rs b/local_player/src/main.rs index 979f43ea..9d07ac27 100644 --- a/local_player/src/main.rs +++ b/local_player/src/main.rs @@ -1,3 +1,5 @@ fn main() { - println!("Hello from local_player member of spotify_player. The player is not implemented yet!"); + println!( + "Hello from local_player member of spotify_player. The player is not implemented yet!" + ); } From 0038d8af10ae152cd14ea9061386c7530c7bc0c1 Mon Sep 17 00:00:00 2001 From: Mani Arasteh Date: Thu, 18 Sep 2025 13:09:18 +0330 Subject: [PATCH 3/3] Add play_music function, not tested --- Cargo.lock | 74 ++++++++++++++++++++++++++++++++++++++++ local_player/Cargo.toml | 2 ++ local_player/src/main.rs | 33 +++++++++++++++++- 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index c06bc2d7..751bbd7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1332,6 +1332,12 @@ dependencies = [ "zune-inflate", ] +[[package]] +name = "extended" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af9673d8203fcb076b19dfd17e38b3d4ae9f44959416ea532ce72415a6020365" + [[package]] name = "fastrand" version = "2.3.0" @@ -2829,6 +2835,10 @@ checksum = "f5e54036fe321fd421e10d732f155734c4e4afd610dd556d9a82833ab3ee0bed" [[package]] name = "local_player" version = "0.1.0" +dependencies = [ + "anyhow", + "rodio", +] [[package]] name = "lock_api" @@ -4459,6 +4469,7 @@ dependencies = [ "cpal", "dasp_sample", "num-rational", + "symphonia", ] [[package]] @@ -5174,11 +5185,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "815c942ae7ee74737bb00f965fa5b5a2ac2ce7b6c01c0cc169bbeaf7abd5f5a9" 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]] @@ -5193,6 +5221,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.4" @@ -5217,6 +5266,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.4" @@ -5229,6 +5291,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.4" diff --git a/local_player/Cargo.toml b/local_player/Cargo.toml index bd39b788..c17fcf07 100644 --- a/local_player/Cargo.toml +++ b/local_player/Cargo.toml @@ -4,6 +4,8 @@ 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 index 9d07ac27..8fe5a0fa 100644 --- a/local_player/src/main.rs +++ b/local_player/src/main.rs @@ -1,5 +1,36 @@ -fn main() { +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(()) }