Search in sources :

Example 81 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project lavaplayer by sedmelluq.

the class StreamAudioPlayerManager method loadFromStream.

private boolean loadFromStream(String identifier, AudioLoadResultHandler resultHandler) {
    try {
        StreamInstance stream;
        synchronized (streams) {
            String finalIdentifier = defaultOnNull(resolutionCache.get(identifier), identifier);
            stream = streams.get(finalIdentifier);
        }
        if (stream != null) {
            AudioTrack track = stream.getTrack().makeClone();
            log.debug("Track {} (originally {}) loaded using existing stream.", track.getIdentifier(), identifier);
            resultHandler.trackLoaded(track);
            return true;
        }
    } catch (Exception e) {
        log.error("Error when checking streams for identifier {}.", identifier);
    }
    return false;
}
Also used : AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 82 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project lavaplayer by sedmelluq.

the class MusicScheduler method startNextTrack.

private void startNextTrack(boolean noInterrupt) {
    AudioTrack next = queue.pollFirst();
    if (next != null) {
        if (!player.startTrack(next, noInterrupt)) {
            queue.addFirst(next);
        }
    } else {
        player.stopTrack();
        messageDispatcher.sendMessage("Queue finished.");
    }
}
Also used : AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 83 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project lavaplayer by sedmelluq.

the class MusicScheduler method updateTrackBox.

private void updateTrackBox(boolean newMessage) {
    AudioTrack track = player.getPlayingTrack();
    if (track == null || newMessage) {
        Message message = boxMessage.getAndSet(null);
        if (message != null) {
            message.delete();
        }
    }
    if (track != null) {
        Message message = boxMessage.get();
        String box = TrackBoxBuilder.buildTrackBox(80, track, player.isPaused(), player.getVolume());
        if (message != null) {
            message.editMessage(box).queue();
        } else {
            if (creatingBoxMessage.compareAndSet(false, true)) {
                messageDispatcher.sendMessage(box, created -> {
                    boxMessage.set(created);
                    creatingBoxMessage.set(false);
                }, error -> {
                    creatingBoxMessage.set(false);
                });
            }
        }
    }
}
Also used : Message(net.dv8tion.jda.api.entities.Message) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 84 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project lavaplayer by sedmelluq.

the class DefaultAudioPlayerManager method decodeTrack.

@Override
public DecodedTrackHolder decodeTrack(MessageInput stream) throws IOException {
    DataInput input = stream.nextMessage();
    if (input == null) {
        return null;
    }
    int version = (stream.getMessageFlags() & TRACK_INFO_VERSIONED) != 0 ? (input.readByte() & 0xFF) : 1;
    AudioTrackInfo trackInfo = new AudioTrackInfo(input.readUTF(), input.readUTF(), input.readLong(), input.readUTF(), input.readBoolean(), version >= 2 ? DataFormatTools.readNullableText(input) : null);
    AudioTrack track = decodeTrackDetails(trackInfo, input);
    long position = input.readLong();
    if (track != null) {
        track.setPosition(position);
    }
    stream.skipRemainingBytes();
    return new DecodedTrackHolder(track);
}
Also used : DataInput(java.io.DataInput) DecodedTrackHolder(com.sedmelluq.discord.lavaplayer.track.DecodedTrackHolder) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) InternalAudioTrack(com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 85 with AudioTrack

use of com.sedmelluq.discord.lavaplayer.track.AudioTrack in project lavaplayer by sedmelluq.

the class DefaultAudioPlayer method checkCleanup.

/**
 * Check if the player should be "cleaned up" - stopped due to nothing using it, with the given threshold.
 * @param threshold Threshold in milliseconds to use
 */
public void checkCleanup(long threshold) {
    AudioTrack track = getPlayingTrack();
    if (track != null && System.currentTimeMillis() - lastRequestTime >= threshold) {
        log.debug("Triggering cleanup on an audio player playing track {}", track);
        stopWithReason(CLEANUP);
    }
}
Also used : InternalAudioTrack(com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Aggregations

AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)85 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)26 ArrayList (java.util.ArrayList)23 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)21 AudioLoadResultHandler (com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler)18 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)17 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)11 List (java.util.List)10 JsonBrowser (com.sedmelluq.discord.lavaplayer.tools.JsonBrowser)9 IOException (java.io.IOException)9 BasicAudioPlaylist (com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist)8 TimeUnit (java.util.concurrent.TimeUnit)7 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)7 YoutubeAudioSourceManager (com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager)6 Optional (java.util.Optional)6 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)6 Permission (net.dv8tion.jda.core.Permission)6 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)5 InternalAudioTrack (com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack)5 Slf4j (lombok.extern.slf4j.Slf4j)5