use of se.light.assembly64.model.SongNotAvailableException in project assembly64fx by freabemania.
the class SidifyMainContoller method playSong.
private SidTune playSong(PlaylistEntry song) throws InterruptedException, SongNotAvailableException, SpecifyFileIdException {
// Ugly, but needed for the nextsub to know
SidTune sidTune = null;
setIconPlaying(true);
Platform.runLater(() -> nowPlaying.setText(song.getNameMasked()));
try {
int retries = 0;
while (true) {
try {
File sid = Support.getSid(song);
if (!sid.exists() && isOffline()) {
throw new SongNotAvailableException();
} else if (!sid.exists()) {
downloadService.downloadTo(sid, song.getId(), song.getCategory(), song.getFileId());
Platform.runLater(() -> {
// update downloaded status
songlist.getColumns().get(0).setVisible(false);
songlist.getColumns().get(0).setVisible(true);
});
}
sidTune = sidPlayService.getSidTune(sid);
sidPlayService.playSid(sidTune, getSongIndex(sidTune) + 1);
break;
} catch (Exception e) {
if (e instanceof SpecifyFileIdException) {
throw e;
} else if (retries > 3 || e instanceof SongNotAvailableException) {
throw e;
}
retries++;
}
}
// load image async
ReturningTask<Void> task = () -> {
if (!Support.isOffline()) {
Set<TargetAndPath> images = MetadataService.getInstance().resolve(song).getImages();
if (images.size() > 0) {
imageView.setImage(new Image(imageCache.getImage(images.iterator().next())));
}
} else {
imageView.setImage(MetadataService.getInstance().getNoPreview());
}
return null;
};
ExecutorUtil.executeAsyncWithRetry(task, 1);
} catch (Exception e) {
if (e instanceof SpecifyFileIdException) {
throw new SpecifyFileIdException();
}
setIconPlaying(false);
progressUpdater.stop();
GenericMessageDialogController.withErrorProps("Sidify", "Sid seems to be broken!", true).showAndWait();
throw new InterruptedException();
}
return sidTune;
}
Aggregations