mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Added repeat support
This commit is contained in:
parent
8971d3aa68
commit
5581289351
1 changed files with 14 additions and 10 deletions
24
src/spirc.rs
24
src/spirc.rs
|
@ -396,6 +396,11 @@ impl SpircTask {
|
||||||
self.notify(None);
|
self.notify(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MessageType::kMessageTypeRepeat => {
|
||||||
|
self.state.set_repeat(frame.get_state().get_repeat());
|
||||||
|
self.notify(None);
|
||||||
|
}
|
||||||
|
|
||||||
MessageType::kMessageTypeSeek => {
|
MessageType::kMessageTypeSeek => {
|
||||||
let position = frame.get_position();
|
let position = frame.get_position();
|
||||||
|
|
||||||
|
@ -467,13 +472,19 @@ impl SpircTask {
|
||||||
|
|
||||||
fn handle_next(&mut self) {
|
fn handle_next(&mut self) {
|
||||||
let current_index = self.state.get_playing_track_index();
|
let current_index = self.state.get_playing_track_index();
|
||||||
let new_index = (current_index + 1) % (self.state.get_track().len() as u32);
|
let num_tracks = self.state.get_track().len() as u32;
|
||||||
|
let new_index = (current_index + 1) % num_tracks;
|
||||||
|
|
||||||
|
let mut was_last_track = (current_index + 1) >= num_tracks;
|
||||||
|
if self.state.get_repeat() {
|
||||||
|
was_last_track = false;
|
||||||
|
}
|
||||||
|
|
||||||
self.state.set_playing_track_index(new_index);
|
self.state.set_playing_track_index(new_index);
|
||||||
self.state.set_position_ms(0);
|
self.state.set_position_ms(0);
|
||||||
self.state.set_position_measured_at(now_ms() as u64);
|
self.state.set_position_measured_at(now_ms() as u64);
|
||||||
|
|
||||||
self.load_track(true);
|
self.load_track(!was_last_track);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_prev(&mut self) {
|
fn handle_prev(&mut self) {
|
||||||
|
@ -520,14 +531,7 @@ impl SpircTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_end_of_track(&mut self) {
|
fn handle_end_of_track(&mut self) {
|
||||||
let current_index = self.state.get_playing_track_index();
|
self.handle_next();
|
||||||
let new_index = (current_index + 1) % (self.state.get_track().len() as u32);
|
|
||||||
|
|
||||||
self.state.set_playing_track_index(new_index);
|
|
||||||
self.state.set_position_ms(0);
|
|
||||||
self.state.set_position_measured_at(now_ms() as u64);
|
|
||||||
|
|
||||||
self.load_track(true);
|
|
||||||
self.notify(None);
|
self.notify(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue