Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 74 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["spotify_player", "lyric_finder"]
members = ["spotify_player", "lyric_finder", "local_player"]
resolver = "2"

[profile.release]
Expand Down
11 changes: 11 additions & 0 deletions local_player/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions local_player/src/main.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
Loading