Merge remote-tracking branch 'realtwister/queue'

This commit is contained in:
Paul Lietar 2016-01-20 13:51:35 +00:00
commit c5ed04f70d

View file

@ -43,7 +43,7 @@ pub trait SpircDelegate {
fn play(&self); fn play(&self);
fn pause(&self); fn pause(&self);
fn seek(&self, position_ms: u32); fn seek(&self, position_ms: u32);
fn volume(&self, vol:i32); fn volume(&self, vol: i32);
fn stop(&self); fn stop(&self);
fn state(&self) -> MutexGuard<Self::State>; fn state(&self) -> MutexGuard<Self::State>;
@ -151,14 +151,7 @@ impl<D: SpircDelegate> SpircManager<D> {
self.became_active_at = util::now_ms(); self.became_active_at = util::now_ms();
} }
self.reload_tracks(&frame);
self.index = frame.get_state().get_playing_track_index();
self.tracks = frame.get_state()
.get_track()
.iter()
.filter(|track| track.has_gid())
.map(|track| SpotifyId::from_raw(track.get_gid()))
.collect();
let play = frame.get_state().get_status() == PlayStatus::kPlayStatusPlay; let play = frame.get_state().get_status() == PlayStatus::kPlayStatusPlay;
let track = self.tracks[self.index as usize]; let track = self.tracks[self.index as usize];
@ -184,19 +177,31 @@ impl<D: SpircDelegate> SpircManager<D> {
protocol::spirc::MessageType::kMessageTypeSeek => { protocol::spirc::MessageType::kMessageTypeSeek => {
self.delegate.seek(frame.get_position()); self.delegate.seek(frame.get_position());
} }
protocol::spirc::MessageType::kMessageTypeReplace => {
self.reload_tracks(&frame);
}
protocol::spirc::MessageType::kMessageTypeNotify => { protocol::spirc::MessageType::kMessageTypeNotify => {
if self.is_active && frame.get_device_state().get_is_active() { if self.is_active && frame.get_device_state().get_is_active() {
self.is_active = false; self.is_active = false;
self.delegate.stop(); self.delegate.stop();
} }
} }
protocol::spirc::MessageType::kMessageTypeVolume =>{ protocol::spirc::MessageType::kMessageTypeVolume => {
self.delegate.volume(frame.get_volume() as i32); self.delegate.volume(frame.get_volume() as i32);
} }
_ => (), _ => (),
} }
} }
fn reload_tracks(&mut self, ref frame: &protocol::spirc::Frame) {
self.index = frame.get_state().get_playing_track_index();
self.tracks = frame.get_state()
.get_track()
.iter()
.filter(|track| track.has_gid())
.map(|track| SpotifyId::from_raw(track.get_gid()))
.collect();
}
fn notify(&mut self, hello: bool, recipient: Option<&str>) { fn notify(&mut self, hello: bool, recipient: Option<&str>) {
let mut pkt = protobuf_init!(protocol::spirc::Frame::new(), { let mut pkt = protobuf_init!(protocol::spirc::Frame::new(), {
version: 1, version: 1,