本文整理汇总了Java中com.sedmelluq.discord.lavaplayer.track.AudioPlaylist类的典型用法代码示例。如果您正苦于以下问题:Java AudioPlaylist类的具体用法?Java AudioPlaylist怎么用?Java AudioPlaylist使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AudioPlaylist类属于com.sedmelluq.discord.lavaplayer.track包,在下文中一共展示了AudioPlaylist类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: playlistLoaded
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
@Override
public void playlistLoaded(AudioPlaylist audioPlaylist) {
for (Iterator<AudioTrack> iterator = audioPlaylist.getTracks().iterator(); iterator.hasNext();) {
AudioTrack audioTrack = iterator.next();
if (audioTrack == null) {
continue;
}
Audio audio = new Audio(getTextChannel(), getMember(), audioTrack);
DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue().add(audio);
if (DiscordBot.getInstance().getDiscord().getAudioPlayer().getPlayingTrack() == null) {
DiscordBot.getInstance().getDiscord().getAudioQueue().playNext();
} else {
LogHelper.debug("'" + audio.getAudioTrack().getInfo().title + "' Has been added to the queue.");
}
audio = null;
}
LogHelper.debug(audioPlaylist.getTracks().size() + " Songs have been added to the queue.");
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl());
embedBuilder.setColor(DiscordUtil.SUCCESS);
embedBuilder.setTitle(audioPlaylist.getTracks().size() + " Songs have been added to the queue.", null);
DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
}
示例2: checkSourcesForItemOnce
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
private AudioItem checkSourcesForItemOnce(AudioReference reference, AudioLoadResultHandler resultHandler, boolean[] reported) {
for (AudioSourceManager sourceManager : sourceManagers) {
AudioItem item = sourceManager.loadItem(this, reference);
if (item != null) {
if (item instanceof AudioTrack) {
log.debug("Loaded a track with identifier {} using {}.", reference.identifier, sourceManager.getClass().getSimpleName());
reported[0] = true;
resultHandler.trackLoaded((AudioTrack) item);
} else if (item instanceof AudioPlaylist) {
log.debug("Loaded a playlist with identifier {} using {}.", reference.identifier, sourceManager.getClass().getSimpleName());
reported[0] = true;
resultHandler.playlistLoaded((AudioPlaylist) item);
}
return item;
}
}
return null;
}
示例3: loadPlaylistWithId
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
private AudioPlaylist loadPlaylistWithId(String playlistId, String selectedVideoId) {
log.debug("Starting to load playlist with ID {}", playlistId);
try (HttpInterface httpInterface = getHttpInterface()) {
try (CloseableHttpResponse response = httpInterface.execute(new HttpGet("https://www.youtube.com/playlist?list=" + playlistId))) {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
throw new IOException("Invalid status code for playlist response: " + statusCode);
}
Document document = Jsoup.parse(response.getEntity().getContent(), CHARSET, "");
return buildPlaylist(httpInterface, document, selectedVideoId);
}
} catch (Exception e) {
throw ExceptionTools.wrapUnfriendlyExceptions(e);
}
}
示例4: loadMixWithId
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
/**
* Loads tracks from mix in parallel into a playlist entry.
*
* @param mixId ID of the mix
* @param selectedVideoId Selected track, {@link AudioPlaylist#getSelectedTrack()} will return this.
* @return Playlist of the tracks in the mix.
*/
public AudioPlaylist loadMixWithId(String mixId, String selectedVideoId) {
List<String> videoIds = new ArrayList<>();
try (HttpInterface httpInterface = sourceManager.getHttpInterface()) {
String mixUrl = "https://www.youtube.com/watch?v=" + selectedVideoId + "&list=" + mixId;
try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(mixUrl))) {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
throw new IOException("Invalid status code for mix response: " + statusCode);
}
Document document = Jsoup.parse(response.getEntity().getContent(), StandardCharsets.UTF_8.name(), "");
extractVideoIdsFromMix(document, videoIds);
}
} catch (IOException e) {
throw new FriendlyException("Could not read mix page.", SUSPICIOUS, e);
}
if (videoIds.isEmpty()) {
throw new FriendlyException("Could not find tracks from mix.", SUSPICIOUS, null);
}
return loadTracksAsynchronously(videoIds, selectedVideoId);
}
示例5: loadTracksAsynchronously
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
private AudioPlaylist loadTracksAsynchronously(List<String> videoIds, String selectedVideoId) {
ExecutorCompletionService<AudioItem> completion = new ExecutorCompletionService<>(mixLoadingExecutor);
List<AudioTrack> tracks = new ArrayList<>();
for (final String videoId : videoIds) {
completion.submit(() -> sourceManager.loadTrackWithVideoId(videoId, true));
}
try {
fetchTrackResultsFromExecutor(completion, tracks, videoIds.size());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
AudioTrack selectedTrack = sourceManager.findSelectedTrack(tracks, selectedVideoId);
if (tracks.isEmpty()) {
throw new FriendlyException("No tracks from the mix loaded succesfully.", SUSPICIOUS, null);
} else if (selectedTrack == null) {
throw new FriendlyException("The selected track of the mix failed to load.", SUSPICIOUS, null);
}
return new BasicAudioPlaylist("YouTube mix", tracks, selectedTrack, false);
}
示例6: loadTrack
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
private void loadTrack(String identifier, Member author, Message msg) {
Guild guild = author.getGuild();
getPlayer(guild);
msg.getTextChannel().sendTyping().queue();
myManager.setFrameBufferDuration(5000);
myManager.loadItemOrdered(guild, identifier, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
getTrackManager(guild).queue(track, author);
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
if (playlist.getSelectedTrack() != null) {
trackLoaded(playlist.getSelectedTrack());
} else if (playlist.isSearchResult()) {
trackLoaded(playlist.getTracks().get(0));
} else {
for (int i = 0; i < Math.min(playlist.getTracks().size(), PLAYLIST_LIMIT); i++) {
getTrackManager(guild).queue(playlist.getTracks().get(i), author);
}
}
}
@Override
public void noMatches() {
}
@Override
public void loadFailed(FriendlyException exception) {
}
});
}
示例7: loadTracks
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
private void loadTracks(AudioTrack track, AudioPlaylist playlist) {
if (VoiceSendHandler.isSongTooLong(track)) {
message.editMessage(commandEvent.getClient().getWarning() + " The track was longer than the max length of " +
QueuedAudioTrack.msToMinSec(VoiceSendHandler.MAX_DURATION * 1000)).queue();
return;
}
// If the queue track was successfull go on, if not return.
if (bot.queueTrack(track, commandEvent, message) && (playlist == null || !commandEvent.getSelfMember().hasPermission(commandEvent.getTextChannel(), Permission.MESSAGE_ADD_REACTION))) {
message.editMessage(commandEvent.getClient().getSuccess() + " Successfully added track to queue.").queue();
}
}
示例8: playlistLoaded
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
@Override
public void playlistLoaded(AudioPlaylist audioPlaylist) {
if (audioPlaylist.isSearchResult() || audioPlaylist.getTracks().size() == 0) {
loadTracks(audioPlaylist.getTracks().get(0), null);
}
else if (audioPlaylist.getSelectedTrack() != null) {
loadTracks(audioPlaylist.getSelectedTrack(), null);
}
else {
loadTracks(audioPlaylist.getTracks().get(0), null);
// TODO: Playlists
}
}
示例9: play
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
public void play(String fileName, Runnable action)
{
this.action = action;
playerManager.loadItem(fileName, new AudioLoadResultHandler()
{
@Override
public void trackLoaded(AudioTrack track)
{
log.info("Attempting to play the requested sound.");
player.playTrack(track);
}
@Override
public void playlistLoaded(AudioPlaylist playlist)
{
}
@Override
public void noMatches()
{
if (action != null)
action.run();
}
@Override
public void loadFailed(FriendlyException exception)
{
}
});
}
示例10: playlistLoaded
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
@Override
public void playlistLoaded(AudioPlaylist audioPlaylist) {
log.error("Loaded playlist instead of stream");
synchronized (this) {
this.notify();
}
}
示例11: loadAndPlay
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
private static void loadAndPlay(final IChannel channel, final String trackUrl) {
GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild());
playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
BotUtils.sendEmbMessage(channel, SMB.shortMessage(String.format(LANG.getTranslation("music_add"), track.getInfo().title)), true);
play(musicManager, track);
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
AudioTrack firstTrack = playlist.getSelectedTrack();
if (firstTrack == null) {
firstTrack = playlist.getTracks().get(0);
}
BotUtils.sendEmbMessage(channel, SMB.shortMessage(String.format(LANG.getTranslation("music_add_queue"), firstTrack.getInfo().title, playlist.getName())), true);
play(musicManager, firstTrack);
}
@Override
public void noMatches() {
BotUtils.sendEmbMessage(channel, SMB.shortMessage(String.format(LANG.getTranslation("music_notfound"), trackUrl)), true);
}
@Override
public void loadFailed(FriendlyException exception) {
BotUtils.sendEmbMessage(channel, SMB.shortMessage(LANG.getTranslation("music_notloaded") + exception.getMessage()), true);
}
});
}
示例12: loadAndPlay
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
/**
* Load a song
* @param channel The channel to send the alert in.
* @param trackUrl The song URL
* @param voiceChannel the voice channel to play the music in.
*/
public void loadAndPlay(final TextChannel channel, final String trackUrl, VoiceChannel voiceChannel) {
GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild());
playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
channel.sendMessage("Adding to queue " + track.getInfo().title).queue();
play(channel.getGuild(), musicManager, track, voiceChannel);
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
AudioTrack firstTrack = playlist.getSelectedTrack();
if (firstTrack == null) {
firstTrack = playlist.getTracks().get(0);
}
channel.sendMessage("Adding to queue " + firstTrack.getInfo().title + " (first track of playlist " + playlist.getName() + ")").queue();
play(channel.getGuild(), musicManager, firstTrack, voiceChannel);
}
@Override
public void noMatches() {
channel.sendMessage("Nothing found by " + trackUrl).queue();
}
@Override
public void loadFailed(FriendlyException exception) {
channel.sendMessage("Could not play: " + exception.getMessage()).queue();
}
});
}
示例13: addMusicOnly
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
/**
* Add a song to the queue of a guild
* @param guild The guild to add the song in
* @param channel The channel to send the alert in.
* @param url The URL of the song.
*/
public void addMusicOnly(Guild guild, MessageChannel channel, String url) {
getPlayerManager().loadItemOrdered(getPlayerManager(), url, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
channel.sendMessage("Adding to queue " + track.getInfo().title).queue();
getGuildAudioPlayer(guild).scheduler.queue(track);
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
AudioTrack firstTrack = playlist.getSelectedTrack();
if (firstTrack == null) {
firstTrack = playlist.getTracks().get(0);
}
channel.sendMessage("Adding to queue " + firstTrack.getInfo().title + " (first track of playlist " + playlist.getName() + ")").queue();
getGuildAudioPlayer(guild).scheduler.queue(firstTrack);
}
@Override
public void noMatches() {
channel.sendMessage("Nothing found by " + url).queue();
}
@Override
public void loadFailed(FriendlyException exception) {
channel.sendMessage("Could not play: " + exception.getMessage()).queue();
}
});
}
示例14: sendPlaylistResponse
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
private void sendPlaylistResponse(Message message, TrackResponse response) {
AudioPlaylist playlist = (AudioPlaylist) response.getAudioItem();
MessageFactory.makeSuccess(message,
":user has added :songs songs from the [:title](:url) playlist to the queue. There are `:queueSize` song(s) ahead of it in the queue."
)
.set("songs", playlist.getTracks().size())
.set("title", playlist.getName())
.set("url", response.getTrackUrl())
.set("queueSize", AudioHandler.getQueueSize(response.getMusicManager()))
.queue();
}
示例15: loadSong
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; //导入依赖的package包/类
private void loadSong(Message message, PlaylistTransformer.PlaylistSong song) {
Metrics.searchRequests.inc();
AudioHandler.AUDIO_PLAYER_MANAGER.loadItemOrdered(AudioHandler.MUSIC_MANAGER, song.getLink(), new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
Metrics.tracksLoaded.inc();
AudioHandler.getGuildAudioPlayer(message.getGuild())
.getScheduler().queue(track, message.getAuthor());
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
trackLoaded(playlist.getTracks().get(0));
}
@Override
public void noMatches() {
Metrics.trackLoadsFailed.inc();
}
@Override
public void loadFailed(FriendlyException exception) {
Metrics.trackLoadsFailed.inc();
}
});
}