diff --git a/src/spirc.rs b/src/spirc.rs index 28831c28..16c26a2f 100644 --- a/src/spirc.rs +++ b/src/spirc.rs @@ -146,18 +146,10 @@ impl SpircManager { .send(); } - pub fn send_replace_tracks, I: Iterator>(&mut self, - recipient: &str, - track_ids: I) { - let tracks: Vec = track_ids.map(|i| { - protobuf_init!(protocol::spirc::TrackRef::new(), { gid: SpotifyId::from_base62(i.as_ref()).to_raw().to_vec()}) - }) - .collect(); - - let state = protobuf_init!(protocol::spirc::State::new(), { - track: RepeatedField::from_vec(tracks) - }); - + pub fn send_replace_tracks>(&mut self, + recipient: &str, + track_ids: I) { + let state = track_ids_to_state(track_ids); let mut internal = self.0.lock().unwrap(); CommandSender::new(&mut *internal, protocol::spirc::MessageType::kMessageTypeReplace) @@ -165,6 +157,18 @@ impl SpircManager { .state(state) .send(); } + + pub fn send_load_tracks>(&mut self, + recipient: &str, + track_ids: I) { + let state = track_ids_to_state(track_ids); + let mut internal = self.0.lock().unwrap(); + CommandSender::new(&mut *internal, + protocol::spirc::MessageType::kMessageTypeLoad) + .recipient(recipient) + .state(state) + .send(); + } } impl SpircInternal { @@ -462,3 +466,14 @@ impl<'a> CommandSender<'a> { .fire(); } } + +fn track_ids_to_state>(track_ids: I) -> protocol::spirc::State { + let tracks: Vec = + track_ids.map(|i| { + protobuf_init!(protocol::spirc::TrackRef::new(), { gid: i.to_raw().to_vec()}) + }) + .collect(); + protobuf_init!(protocol::spirc::State::new(), { + track: RepeatedField::from_vec(tracks) + }) +}