public synchronized void next(AudioTrack last) { AudioTrack track; if (repeat && last != null) { track = last.makeClone(); } else { if (loop && last != null) { queue.add(last.makeClone()); } track = queue.poll(); // potential fix #84 if (track != null) { track = track.makeClone(); } } if (!player.startTrack(track, false)) { musicManager.getConnector().closeConnection(); } }
@Override public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) { if (endReason.mayStartNext) { if (isInRepeatMode()) { player.startTrack(track.makeClone(), false); return; } skipTrack(); } } }
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; }
@Override public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) { if (endReason.mayStartNext) { if (manager.isRepeatQueue()) { if (audioTrackContainer == null) { // This should never be null since the container is set when we queue a // track, and this even should only be fired when an track has ended. throw new IllegalStateException("Music track has ended while the audio track container is NULL"); } queue.offer(new AudioTrackContainer(track.makeClone(), audioTrackContainer.getRequester())); } nextTrack(); } else if (endReason.equals(AudioTrackEndReason.FINISHED) && queue.isEmpty()) { if (manager.getLastActiveMessage() != null) { service.submit(() -> handleEndOfQueueWithLastActiveMessage(true)); } } }
public void skipTrack() { trackEnded(); if (isInRepeatMode() && player.getPlayingTrack() != null) { player.startTrack(player.getPlayingTrack().makeClone(), false); return; } player.stopTrack(); QueuedAudioTrack poll = queue.poll(); if (poll != null) { lastRequester = poll.getUserId(); player.startTrack(poll.getTrack(), false); } }
@Override public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) { // if the track ended normally, and we're in repeat mode, re-add it to the queue if(endReason==AudioTrackEndReason.FINISHED && manager.getBot().getSettingsManager().getSettings(guildId).getRepeatMode()) { queue.add(new QueuedTrack(track.makeClone(), track.getUserData(Long.class)==null ? 0L : track.getUserData(Long.class))); } if(queue.isEmpty()) { if(!playFromDefault()) { manager.getBot().getNowplayingHandler().onTrackUpdate(guildId, null, this); if(!manager.getBot().getConfig().getStay()) manager.getBot().closeAudioConnection(guildId); } } else { QueuedTrack qt = queue.pull(); player.playTrack(qt.getTrack()); } }