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;
}
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.");
}
}
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);
});
}
}
}
}
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);
}
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);
}
}
Aggregations