mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Tweak track loading
This commit is contained in:
parent
b96405af82
commit
508c7e2b26
1 changed files with 15 additions and 8 deletions
|
@ -13,7 +13,7 @@ use context::StationContext;
|
|||
use librespot_core::config::ConnectConfig;
|
||||
use librespot_core::mercury::MercuryError;
|
||||
use librespot_core::session::Session;
|
||||
use librespot_core::spotify_id::{SpotifyId, SpotifyIdError};
|
||||
use librespot_core::spotify_id::{SpotifyAudioType, SpotifyId, SpotifyIdError};
|
||||
use librespot_core::util::SeqGenerator;
|
||||
use librespot_core::version;
|
||||
use librespot_core::volume::Volume;
|
||||
|
@ -825,31 +825,38 @@ impl SpircTask {
|
|||
fn load_track(&mut self, play: bool) {
|
||||
let context_uri = self.state.get_context_uri().to_owned();
|
||||
let mut index = self.state.get_playing_track_index();
|
||||
let start_index = index;
|
||||
let tracks_len = self.state.get_track().len() as u32;
|
||||
debug!(
|
||||
"Loading context: {} index: [{}] of {}",
|
||||
"Loading context: <{}> index: [{}] of {}",
|
||||
context_uri, index, tracks_len
|
||||
);
|
||||
// Tracks either have a gid or uri.
|
||||
// Context based frames sometimes use spotify:meta:page: that needs to be ignored.
|
||||
// Cycle through all tracks, break if we don't find any playable tracks
|
||||
// TODO: This will panic if no playable tracks are found!
|
||||
// tracks in each frame either have a gid or uri (that may or may not be a valid track)
|
||||
// E.g - context based frames sometimes contain tracks with <spotify:meta:page:>
|
||||
let track = {
|
||||
let mut track_ref = &self.state.get_track()[index as usize];
|
||||
let mut track_id = self.get_spotify_id_for_track(track_ref);
|
||||
while track_id.is_err() {
|
||||
while track_id.is_err() || track_id.unwrap().audio_type == SpotifyAudioType::NonPlayable {
|
||||
warn!(
|
||||
"Skipping track {:?} at position [{}] of {}",
|
||||
"Skipping track <{:?}> at position [{}] of {}",
|
||||
track_ref.get_uri(),
|
||||
index,
|
||||
tracks_len
|
||||
);
|
||||
// This will keep looping over, instead we should cylce tracks only once
|
||||
index = if index + 1 < tracks_len { index + 1 } else { 0 };
|
||||
if index == start_index {
|
||||
warn!("No playable track found in state: {:?}", self.state);
|
||||
break;
|
||||
}
|
||||
self.state.set_playing_track_index(index);
|
||||
track_ref = &self.state.get_track()[index as usize];
|
||||
track_id = self.get_spotify_id_for_track(track_ref);
|
||||
}
|
||||
track_id
|
||||
}
|
||||
.unwrap();
|
||||
.expect("Invalid SpotifyId");
|
||||
|
||||
let position = self.state.get_position_ms();
|
||||
let end_of_track = self.player.load(track, play, position);
|
||||
|
|
Loading…
Reference in a new issue