Tracks: Simplify track end event handler (#77)
This commit is contained in:
committed by
GitHub
parent
9e202f602d
commit
c97f23ee27
@@ -105,21 +105,16 @@ impl EventHandler for QueueHandler {
|
|||||||
// Due to possibility that users might remove, reorder,
|
// Due to possibility that users might remove, reorder,
|
||||||
// or dequeue+stop tracks, we need to verify that the FIRST
|
// or dequeue+stop tracks, we need to verify that the FIRST
|
||||||
// track is the one who has ended.
|
// track is the one who has ended.
|
||||||
let front_ended = match ctx {
|
match ctx {
|
||||||
EventContext::Track(ts) => {
|
EventContext::Track(ts) => {
|
||||||
// This slice should have exactly one entry.
|
// This slice should have exactly one entry.
|
||||||
// If the ended track has same id as the queue head, then
|
// If the ended track has same id as the queue head, then
|
||||||
// we can progress the queue.
|
// we can progress the queue.
|
||||||
let queue_uuid = inner.tracks.front().map(|handle| handle.uuid());
|
if inner.tracks.front()?.uuid() != ts.first()?.1.uuid() {
|
||||||
let ended_uuid = ts.first().map(|handle| handle.1.uuid());
|
return None;
|
||||||
|
}
|
||||||
queue_uuid.is_some() && queue_uuid == ended_uuid
|
|
||||||
},
|
},
|
||||||
_ => false,
|
_ => return None,
|
||||||
};
|
|
||||||
|
|
||||||
if !front_ended {
|
|
||||||
return None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let _old = inner.tracks.pop_front();
|
let _old = inner.tracks.pop_front();
|
||||||
@@ -128,16 +123,13 @@ impl EventHandler for QueueHandler {
|
|||||||
info!("{} tracks remain.", inner.tracks.len());
|
info!("{} tracks remain.", inner.tracks.len());
|
||||||
|
|
||||||
// Keep going until we find one track which works, or we run out.
|
// Keep going until we find one track which works, or we run out.
|
||||||
let mut keep_looking = true;
|
while let Some(new) = inner.tracks.front() {
|
||||||
while keep_looking && !inner.tracks.is_empty() {
|
if new.play().is_err() {
|
||||||
if let Some(new) = inner.tracks.front() {
|
|
||||||
keep_looking = new.play().is_err();
|
|
||||||
|
|
||||||
// Discard files which cannot be used for whatever reason.
|
// Discard files which cannot be used for whatever reason.
|
||||||
if keep_looking {
|
warn!("Track in Queue couldn't be played...");
|
||||||
warn!("Track in Queue couldn't be played...");
|
inner.tracks.pop_front();
|
||||||
let _ = inner.tracks.pop_front();
|
} else {
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user