Search in sources :

Example 1 with SongNotAvailableException

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;
}
Also used : SpecifyFileIdException(se.light.assembly64.model.SpecifyFileIdException) Set(java.util.Set) SongNotAvailableException(se.light.assembly64.model.SongNotAvailableException) Image(javafx.scene.image.Image) SidTune(libsidplay.sidtune.SidTune) File(java.io.File) SearchException(se.light.assembly64.model.SearchException) SongNotAvailableException(se.light.assembly64.model.SongNotAvailableException) SpecifyFileIdException(se.light.assembly64.model.SpecifyFileIdException)

Aggregations

File (java.io.File)1 Set (java.util.Set)1 Image (javafx.scene.image.Image)1 SidTune (libsidplay.sidtune.SidTune)1 SearchException (se.light.assembly64.model.SearchException)1 SongNotAvailableException (se.light.assembly64.model.SongNotAvailableException)1 SpecifyFileIdException (se.light.assembly64.model.SpecifyFileIdException)1