lavalink.client.player.LavalinkPlayer Java Examples
The following examples show how to use
lavalink.client.player.LavalinkPlayer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LavalinkUtil.java From Lavalink-Client with MIT License | 5 votes |
/** * * @param player the lavalink player that holds the track with data * @param message the Base64 audio track * @return the AudioTrack with the user data stored in the player * @throws IOException if there is an IO problem */ public static AudioTrack toAudioTrackWithData(LavalinkPlayer player, String message) throws IOException{ AudioTrack storedTrack = player.getPlayingTrack(); AudioTrack messageTrack = toAudioTrack(message); if (storedTrack != null && storedTrack.getUserData() != null) { messageTrack.setUserData(storedTrack.getUserData()); } return messageTrack; }
Example #2
Source File: TrackScheduler.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
private void onStop() { //stop the track. LavalinkPlayer lavalinkPlayer = getAudioPlayer().getPlayer(); if (lavalinkPlayer.getPlayingTrack() != null) lavalinkPlayer.stopTrack(); getVoteStop().clear(); getVoteSkips().clear(); Guild g = getGuild(); if (g == null) { //Why? this.getAudioPlayer().destroy(); return; } boolean premium = MantaroData.db().getGuild(g).isPremium(); try { TextChannel ch = getRequestedTextChannel(); if (ch != null && ch.canTalk()) { ch.sendMessageFormat( language.get("commands.music_general.queue_finished"), EmoteReference.MEGA, premium ? "" : String.format(language.get("commands.music_general.premium_beg"), EmoteReference.HEART) ).queue(message -> message.delete().queueAfter(30, TimeUnit.SECONDS)); } } catch (Exception e) { Sentry.capture(e); } requestedChannel = 0; errorCount = 0; //If not set to null, those two objects will always be in scope and dangle around in the heap forever. //Some AudioTrack objects were of almost 500kb of size, I guess 100k of those can cause a meme. currentTrack = null; previousTrack = null; //Disconnect this audio player. this.getAudioPlayer().disconnect(); }
Example #3
Source File: MusicCmds.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
@Subscribe public void reset(CommandRegistry cr) { cr.register("restartsong", new SimpleCommand(CommandCategory.MUSIC) { @Override protected void call(Context ctx, String content, String[] args) { GuildMusicManager manager = ctx.getAudioManager().getMusicManager(ctx.getGuild()); LavalinkPlayer lavalinkPlayer = manager.getLavaLink().getPlayer(); if (lavalinkPlayer.getPlayingTrack() == null) { ctx.sendLocalized("commands.music_general.not_playing", EmoteReference.ERROR); return; } if (isDJ(ctx.getMember())) { lavalinkPlayer.seekTo(1); ctx.sendLocalized("commands.restartsong.success", EmoteReference.CORRECT); } else { ctx.sendLocalized("commands.music_general.dj_only", EmoteReference.ERROR); } } @Override public HelpContent help() { return new HelpContent.Builder() .setDescription("Restarts the playback of the current song.") .build(); } }); }
Example #4
Source File: AudioMessageManager.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
private EmbedBuilder getPlayMessage(TrackRequest request) { EmbedBuilder builder = getBasicMessage(request); builder.setDescription(null); AudioTrackInfo info = request.getTrack().getInfo(); PlaybackInstance instance = TrackData.get(request.getTrack()).getInstance(); boolean refreshable = isRefreshable(instance.getGuildId()); String durationText; if (request.getEndReason() != null) { StringBuilder reasonBuilder = new StringBuilder(); boolean hasDuration = !info.isStream && info.length > 0; if (hasDuration) { reasonBuilder.append(CommonUtils.formatDuration(request.getTrack().getDuration())).append(" ("); } reasonBuilder.append(messageService.getEnumTitle(request.getEndReason())); String endMember = getMemberName(request, true); if (StringUtils.isNotBlank(endMember)) { reasonBuilder .append(" - **") .append(endMember) .append("**"); } if (hasDuration) { reasonBuilder.append(")"); } reasonBuilder.append(CommonUtils.EMPTY_SYMBOL); durationText = reasonBuilder.toString(); } else { durationText = getTextProgress(instance, request.getTrack(), refreshable); } if (instance.getPlaylistUuid() != null) { builder.setDescription(messageService.getMessage("discord.command.audio.panel.playlist", commonProperties.getBranding().getWebsiteUrl(), instance.getPlaylistUuid())); } int size = instance.getQueue().size(); if (request.getEndReason() == null && size > 1) { MusicConfig config = musicConfigService.getByGuildId(instance.getGuildId()); if (config != null && config.isShowQueue()) { List<TrackRequest> next = instance.getQueue().subList(1, Math.min(size, MAX_SHORT_QUEUE + 1)); addQueue(builder, instance, next, 2 + instance.getCursor(), true); } } if (request.getTrack().getInfo().isStream || !refreshable) { builder.addField(messageService.getMessage("discord.command.audio.panel.duration"), durationText, true); builder.addField(messageService.getMessage("discord.command.audio.panel.requestedBy"), getMemberName(request, false), true); } else { String requestedBy = String.format("%s: %s", messageService.getMessage("discord.command.audio.panel.requestedBy"), getMemberName(request, false)); builder.addField(requestedBy, durationText, true); } if (request.getEndReason() == null) { IPlayer player = instance.getPlayer(); if (player.getVolume() != 100) { int volume = player.getVolume(); builder.addField(messageService.getMessage("discord.command.audio.panel.volume"), String.format("%d%% %s", volume, CommonUtils.getVolumeIcon(volume)), true); } if (!RepeatMode.NONE.equals(instance.getMode())) { builder.addField(messageService.getMessage("discord.command.audio.panel.repeatMode"), instance.getMode().getEmoji(), true); } if (player.isPaused()) { builder.addField(messageService.getMessage("discord.command.audio.panel.paused"), "\u23F8", true); } if (player instanceof LavalinkPlayer) { LavalinkPlayer lavalinkPlayer = (LavalinkPlayer) player; Link link = lavalinkPlayer.getLink(); if (link != null) { LavalinkSocket socket = link.getNode(false); if (socket != null) { StringBuilder statsBuilder = new StringBuilder(messageService .getMessage("discord.command.audio.panel.poweredBy", socket.getName())); if (refreshable && socket.getStats() != null) { long load = Math.round(socket.getStats().getSystemLoad() * 100); if (load < 0) load = 0; if (load > 100) load = 100; statsBuilder .append(" ") .append(messageService.getMessage("discord.command.audio.panel.load", load)); } builder.setFooter(statsBuilder.toString(), null); } } } } return builder; }
Example #5
Source File: MusicCmds.java From MantaroBot with GNU General Public License v3.0 | 4 votes |
@Subscribe public void rewind(CommandRegistry cr) { cr.register("rewind", new SimpleCommand(CommandCategory.MUSIC) { @Override protected void call(Context ctx, String content, String[] args) { if (args.length == 0) { ctx.sendLocalized("commands.rewind.no_time", EmoteReference.ERROR); return; } GuildMusicManager manager = ctx.getAudioManager().getMusicManager(ctx.getGuild()); LavalinkPlayer lavalinkPlayer = manager.getLavaLink().getPlayer(); if (lavalinkPlayer.getPlayingTrack() == null) { ctx.sendLocalized("commands.music_general.not_playing", EmoteReference.ERROR); return; } if (isDJ(ctx.getMember())) { try { long amt = Utils.parseTime(args[0]); if (amt < 0) { ctx.sendLocalized("commands.rewind.negative", EmoteReference.ERROR); return; } long position = lavalinkPlayer.getTrackPosition(); if (position - amt < 0) { ctx.sendLocalized("commands.rewind.before_beginning", EmoteReference.ERROR); return; } lavalinkPlayer.seekTo(position - amt); ctx.sendLocalized("commands.rewind.success", EmoteReference.CORRECT, AudioUtils.getLength(position - amt)); } catch (NumberFormatException ex) { ctx.sendLocalized("general.invalid_number", EmoteReference.ERROR); } } else { ctx.sendLocalized("commands.music_general.dj_only", EmoteReference.ERROR); } } @Override public HelpContent help() { return new HelpContent.Builder() .setDescription("Rewind the current song a specified amount of time.") .setUsage("~>rewind <time>") .addParameter("time", "The amount of minutes to rewind. Time is in this format: 1m29s (1 minute and 29s), for example.") .build(); } }); }
Example #6
Source File: MusicCmds.java From MantaroBot with GNU General Public License v3.0 | 4 votes |
@Subscribe public void skipahead(CommandRegistry cr) { cr.register("forward", new SimpleCommand(CommandCategory.MUSIC) { @Override protected void call(Context ctx, String content, String[] args) { if (args.length == 0) { ctx.sendLocalized("commands.skipahead.no_time", EmoteReference.ERROR); return; } GuildMusicManager manager = ctx.getAudioManager().getMusicManager(ctx.getGuild()); LavalinkPlayer lavalinkPlayer = manager.getLavaLink().getPlayer(); if (lavalinkPlayer.getPlayingTrack() == null) { ctx.sendLocalized("commands.music_general.not_playing", EmoteReference.ERROR); return; } if (isDJ(ctx.getMember())) { try { long amt = Utils.parseTime(args[0]); if (amt < 0) { //same as in rewind here ctx.sendLocalized("commands.rewind.negative", EmoteReference.ERROR); return; } AudioTrack track = lavalinkPlayer.getPlayingTrack(); long position = lavalinkPlayer.getTrackPosition(); if (position + amt > track.getDuration()) { ctx.sendLocalized("commands.skipahead.past_duration", EmoteReference.ERROR); return; } lavalinkPlayer.seekTo(position + amt); ctx.sendLocalized("commands.skipahead.success", EmoteReference.CORRECT, AudioUtils.getLength(position + amt)); } catch (NumberFormatException ex) { ctx.sendLocalized("general.invalid_number", EmoteReference.ERROR); } } else { ctx.sendLocalized("commands.music_general.dj_only", EmoteReference.ERROR); } } @Override public HelpContent help() { return new HelpContent.Builder() .setDescription("Fast forwards the current song a specified amount of time.") .setUsage("~>forward <time>") .addParameter("time", "The amount of minutes to rewind. Time is in this format: 1m29s (1 minute and 29s), for example.") .build(); } }); cr.registerAlias("forward", "skipahead"); }