Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracks: Simplify track end event handler #77

Merged
merged 1 commit into from
Jun 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions src/tracks/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,16 @@ impl EventHandler for QueueHandler {
// Due to possibility that users might remove, reorder,
// or dequeue+stop tracks, we need to verify that the FIRST
// track is the one who has ended.
let front_ended = match ctx {
match ctx {
EventContext::Track(ts) => {
// This slice should have exactly one entry.
// If the ended track has same id as the queue head, then
// we can progress the queue.
let queue_uuid = inner.tracks.front().map(|handle| handle.uuid());
let ended_uuid = ts.first().map(|handle| handle.1.uuid());

queue_uuid.is_some() && queue_uuid == ended_uuid
if inner.tracks.front()?.uuid() != ts.first()?.1.uuid() {
return None;
}
},
_ => false,
};

if !front_ended {
return None;
_ => return None,
}

let _old = inner.tracks.pop_front();
Expand All @@ -128,16 +123,13 @@ impl EventHandler for QueueHandler {
info!("{} tracks remain.", inner.tracks.len());

// Keep going until we find one track which works, or we run out.
let mut keep_looking = true;
while keep_looking && !inner.tracks.is_empty() {
if let Some(new) = inner.tracks.front() {
keep_looking = new.play().is_err();

while let Some(new) = inner.tracks.front() {
if new.play().is_err() {
// Discard files which cannot be used for whatever reason.
if keep_looking {
warn!("Track in Queue couldn't be played...");
let _ = inner.tracks.pop_front();
}
warn!("Track in Queue couldn't be played...");
inner.tracks.pop_front();
} else {
break;
}
}

Expand Down