fix: fixed self contained references

This commit is contained in:
Nickiel12 2022-12-23 23:24:43 -08:00
parent 9fd012f4b5
commit 135b4f1697
2 changed files with 8 additions and 6 deletions

View file

@ -180,7 +180,7 @@ fn handle_uirequest(
"Switching song to: '{}'", "Switching song to: '{}'",
items.get(0).unwrap().title.clone() 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()); println!("{}", items.get(0).unwrap().path.clone());
write_to_socket(socket, "Switching now playing".to_string(), items) write_to_socket(socket, "Switching now playing".to_string(), items)

View file

@ -4,13 +4,14 @@ use std::io::BufReader;
use crate::message_types::ItemTag; use crate::message_types::ItemTag;
pub struct MusicPlayer { pub struct MusicPlayer<'a> {
output_stream_handle: &'a OutputStreamHandle,
playing_sink: rodio::Sink, playing_sink: rodio::Sink,
currently_playing: ItemTag, currently_playing: ItemTag,
} }
impl MusicPlayer { impl<'a> MusicPlayer<'a> {
pub fn new(starting_item: ItemTag, output_stream_handle: &OutputStreamHandle) -> Self { pub fn new (starting_item: ItemTag, output_stream_handle: &'a OutputStreamHandle) -> Self {
let sink = Sink::try_new(&output_stream_handle).unwrap(); let sink = Sink::try_new(&output_stream_handle).unwrap();
@ -25,6 +26,7 @@ impl MusicPlayer {
//mp.pause(); //mp.pause();
let mp = MusicPlayer { let mp = MusicPlayer {
output_stream_handle,
playing_sink: sink, playing_sink: sink,
currently_playing: starting_item, currently_playing: starting_item,
}; };
@ -41,10 +43,10 @@ impl MusicPlayer {
} }
// TODO: set these to return results // 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(); let source = Decoder::new(BufReader::new(File::open(item.path.clone()).unwrap())).unwrap();
self.playing_sink.stop(); 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); self.playing_sink.append(source);
} }
} }