diff --git a/src/main.rs b/src/main.rs index 5095bbd..81fcd3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -180,7 +180,7 @@ fn handle_uirequest( "Switching song to: '{}'", items.get(0).unwrap().title.clone() ); - music_player.change_now_playing(items.get(0).unwrap().clone(), stream_handle); + music_player.change_now_playing(items.get(0).unwrap().clone()); println!("{}", items.get(0).unwrap().path.clone()); write_to_socket(socket, "Switching now playing".to_string(), items) diff --git a/src/music_player.rs b/src/music_player.rs index 076c2bc..2285174 100644 --- a/src/music_player.rs +++ b/src/music_player.rs @@ -4,13 +4,14 @@ use std::io::BufReader; use crate::message_types::ItemTag; -pub struct MusicPlayer { +pub struct MusicPlayer<'a> { + output_stream_handle: &'a OutputStreamHandle, playing_sink: rodio::Sink, currently_playing: ItemTag, } -impl MusicPlayer { - pub fn new(starting_item: ItemTag, output_stream_handle: &OutputStreamHandle) -> Self { +impl<'a> MusicPlayer<'a> { + pub fn new (starting_item: ItemTag, output_stream_handle: &'a OutputStreamHandle) -> Self { let sink = Sink::try_new(&output_stream_handle).unwrap(); @@ -25,6 +26,7 @@ impl MusicPlayer { //mp.pause(); let mp = MusicPlayer { + output_stream_handle, playing_sink: sink, currently_playing: starting_item, }; @@ -41,10 +43,10 @@ impl MusicPlayer { } // TODO: set these to return results - pub fn change_now_playing(self: &mut Self, item: ItemTag, output_stream_handle: &OutputStreamHandle) { + pub fn change_now_playing(self: &mut Self, item: ItemTag) { let source = Decoder::new(BufReader::new(File::open(item.path.clone()).unwrap())).unwrap(); self.playing_sink.stop(); - self.playing_sink = Sink::try_new(output_stream_handle).unwrap(); + self.playing_sink = Sink::try_new(self.output_stream_handle).unwrap(); self.playing_sink.append(source); } }