Search in sources :

Example 1 with SidTune

use of libsidplay.sidtune.SidTune 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)

Example 2 with SidTune

use of libsidplay.sidtune.SidTune in project assembly64fx by freabemania.

the class SidifyPlaySingleSidController method init.

public void init(File sid) {
    try {
        final IniConfig config = new IniConfig(true);
        songName.setText(sid.getName());
        SidTune tune = SidTune.load(sid);
        tune.getInfo().setSelectedSong(null);
        player = new Player(config);
        player.setTune(tune);
        player.getTimer().setStart(0);
        player.startC64();
        playing = true;
    } catch (Exception e) {
        LOGGER.error("Unable to play sid", e);
        throw new RuntimeException(e);
    }
}
Also used : IniConfig(sidplay.ini.IniConfig) Player(sidplay.Player) SidTune(libsidplay.sidtune.SidTune)

Aggregations

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