Skip to content

Commit

Permalink
Play an alternative track if selected one is not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
plietar committed Dec 28, 2015
1 parent 4f518fc commit 17d4534
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/player.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use eventual::Async;
use eventual::{self, Async};
use portaudio;
use std::sync::{mpsc, Mutex, Arc, Condvar, MutexGuard};
use std::thread;
use vorbis;

use metadata::Track;
use metadata::{Track, TrackRef};
use session::Session;
use audio_decrypt::AudioDecrypt;
use util::{self, SpotifyId, Subfile};
Expand Down Expand Up @@ -97,8 +97,17 @@ impl PlayerInternal {
state.position_measured_at = util::now_ms();
return true;
});
drop(decoder);

let track = self.session.metadata::<Track>(track_id).await().unwrap();
let mut track = self.session.metadata::<Track>(track_id).await().unwrap();

if !track.available {
let alternatives = track.alternatives.iter()
.map(|alt_id| self.session.metadata::<Track>(*alt_id))
.collect::<Vec<TrackRef>>();

track = eventual::sequence(alternatives.into_iter()).iter().find(|alt| alt.available).unwrap();
}

let file_id = track.files[0];

Expand Down

0 comments on commit 17d4534

Please sign in to comment.