Search in sources :

Example 1 with UrlPlayable

use of net.robinfriedli.aiode.audio.UrlPlayable in project aiode by robinfriedli.

the class AbstractPlayableLoadingCommand method loadSoundCloudTrack.

private void loadSoundCloudTrack(AudioManager audioManager) {
    AudioTrackLoader audioTrackLoader = new AudioTrackLoader(audioManager.getPlayerManager());
    String commandInput = getCommandInput();
    AudioItem audioItem = audioTrackLoader.loadByIdentifier("scsearch:" + commandInput);
    if (audioItem instanceof AudioTrack) {
        AudioTrack audioTrack = (AudioTrack) audioItem;
        handleResults(Lists.newArrayList(new UrlPlayable(audioTrack)));
        this.loadedAudioTrack = audioTrack;
    } else if (audioItem == null) {
        throw new NoResultsFoundException(String.format("No soundcloud track found for '%s'", commandInput));
    } else if (audioItem instanceof AudioPlaylist) {
        int limit = getArgumentValueWithTypeOrElse("select", Integer.class, 20);
        List<AudioTrack> tracks = ((AudioPlaylist) audioItem).getTracks();
        if (tracks.isEmpty()) {
            throw new NoResultsFoundException(String.format("No soundcloud track found for '%s'", commandInput));
        }
        if (tracks.size() > limit) {
            tracks = tracks.subList(0, limit);
        }
        askQuestion(tracks, audioTrack -> audioTrack.getInfo().title, audioTrack -> audioTrack.getInfo().author);
    }
}
Also used : UrlPlayable(net.robinfriedli.aiode.audio.UrlPlayable) NoResultsFoundException(net.robinfriedli.aiode.exceptions.NoResultsFoundException) AudioTrackLoader(net.robinfriedli.aiode.audio.AudioTrackLoader) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioItem(com.sedmelluq.discord.lavaplayer.track.AudioItem) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)

Aggregations

AudioItem (com.sedmelluq.discord.lavaplayer.track.AudioItem)1 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)1 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 AudioTrackLoader (net.robinfriedli.aiode.audio.AudioTrackLoader)1 UrlPlayable (net.robinfriedli.aiode.audio.UrlPlayable)1 NoResultsFoundException (net.robinfriedli.aiode.exceptions.NoResultsFoundException)1