mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
Add function for sending load comand.
This commit is contained in:
parent
5e3404137f
commit
8e0325c297
1 changed files with 27 additions and 12 deletions
39
src/spirc.rs
39
src/spirc.rs
|
@ -146,18 +146,10 @@ impl SpircManager {
|
|||
.send();
|
||||
}
|
||||
|
||||
pub fn send_replace_tracks<S: AsRef<str>, I: Iterator<Item = S>>(&mut self,
|
||||
recipient: &str,
|
||||
track_ids: I) {
|
||||
let tracks: Vec<protocol::spirc::TrackRef> = 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<I: Iterator<Item = SpotifyId>>(&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<I: Iterator<Item = SpotifyId>>(&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<I: Iterator<Item = SpotifyId>>(track_ids: I) -> protocol::spirc::State {
|
||||
let tracks: Vec<protocol::spirc::TrackRef> =
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue