/** * Gets the progress bar for the current {@link Track} including the percent played. * * @param track The {@link Track} to get a progress bar for. * @return A string the represents a progress bar that represents the time played. */ public static String getProgressBar(Track track) { float percentage = (100f / track.getTrack().getDuration() * track.getTrack().getPosition()); return "[" + StringUtils.repeat("▬", (int) Math.round((double) percentage / 10)) + "](https://github.com/FlareBot)" + StringUtils.repeat("▬", 10 - (int) Math.round((double) percentage / 10)) + " " + GeneralUtils.percentageFormat.format(percentage) + "%"; }
@Override public void encodeTrack(MessageOutput stream, AudioTrack track) throws IOException { DataOutput output = stream.startMessage(); output.write(TRACK_INFO_VERSION); AudioTrackInfo trackInfo = track.getInfo(); output.writeUTF(trackInfo.title); output.writeUTF(trackInfo.author); output.writeLong(trackInfo.length); output.writeUTF(trackInfo.identifier); output.writeBoolean(trackInfo.isStream); DataFormatTools.writeNullableText(output, trackInfo.uri); encodeTrackDetails(track, output); output.writeLong(track.getPosition()); stream.commitMessage(TRACK_INFO_VERSIONED); }
public String getFormattedPlayedTime() { return NumberUtil.formatTime(getAudioTrack().getPosition()); }
/** * Create the audio cache instance using the given audio track container. * * @param container The audio track container that should be * used to create the audio cache instance. */ AudioCache(AudioTrackContainer container) { this( container.getAudioTrack().getInfo().uri, container.getRequester().getIdLong(), container.getAudioTrack().getPosition() ); }
public Songs(Track track) { title = track.getTrack().getInfo().title; identifier = track.getTrack().getIdentifier(); requester = track.getMeta().getOrDefault("requester", "Unknown").toString(); length = track.getTrack().getDuration(); progress = track.getTrack().getPosition(); User user = Getters.getUserById(requester); if (user != null) { discrim = user.getDiscriminator(); name = user.getName(); avatar = user.getEffectiveAvatarUrl(); } }
track.getInfo().author, formatDuration(track.getPosition()), formatTrackDuration(track))); playing.getInfo().author, formatDuration(playing.getPosition()), formatTrackDuration(playing))); } else { builder.append(String.format(CURRENT_LINE, playing.getInfo().title, playing.getInfo().author, formatDuration(playing.getPosition()) + "/" + formatTrackDuration(playing)));
embed.setTitle("\uD83C\uDFB6 " + record.youtubeTitle, null); embed.setDescription("[source](https://www.youtube.com/watch?v=" + record.youtubecode + ") | `" + DisUtil.getCommandPrefix(player.getGuild()) + "pl` - " + player.getPlaylist().title); embed.addField("duration", Misc.getDurationString(player.player.getPlayingTrack().getPosition() / 1000) + " / " + Misc.getDurationString(record.duration), true); String optionsField = ""; if (player.getRequiredVotes() != 1) {
(isPlaying ? track.getTrack().getPosition() + "/" + track.getTrack().getDuration() : "N/A"), player.getPaused(), player.getPlaylist().size(),
private String buildQueueLength(GuildMusicManager manager) { long length = 0L; for (AudioTrackContainer container : manager.getScheduler().getQueue()) { if (container.getAudioTrack().getInfo().isStream) { continue; } length += container.getAudioTrack().getDuration() / 1000L; } AudioTrack playingTrack = manager.getPlayer().getPlayingTrack(); if (playingTrack != null && !playingTrack.getInfo().isStream) { length += (playingTrack.getDuration() - playingTrack.getPosition()) / 1000L; } int seconds = (int) (length % 60L); int minutes = (int) ((length % 3600L) / 60L); int hours = (int) (length / 3600L); if (hours != 0) { return hours + " hours, " + minutes + " minutes, and " + seconds + " seconds"; } else if (minutes != 0) { return minutes + " minutes, and " + seconds + " seconds"; } return seconds + " seconds"; } }
/** * Creates the audio state by copying the currently playing track, the volume, * voice and channel IDs used for the music, guild ID, as well as all the * tracks in the queue, the audio state can be used when the bot shuts * down, to save it all the cache, or when the bot starts back up * again, to load everything back into the music player. * * @param musicManager The guild music manager that the audio state should be created for. * @param guild The JDA guild object for the current guild music manager. */ public AudioState(GuildMusicManager musicManager, Guild guild) { this.volume = musicManager.getPlayer().getVolume(); this.guildId = guild.getIdLong(); VoiceChannel channel = LavalinkManager.LavalinkManagerHolder.lavalink.getConnectedChannel(guild); voiceChannelId = channel != null ? channel.getIdLong() : 0L; messageChannelId = musicManager.getLastActiveMessage() != null ? musicManager.getLastActiveMessage().getChannel().getIdLong() : 0L; AudioTrack playingTrack = musicManager.getPlayer().getPlayingTrack(); AudioTrackContainer container = musicManager.getScheduler().getAudioTrackContainer(); this.playingTrack = playingTrack == null ? null : new AudioCache( playingTrack.getInfo().uri, container != null ? container.getRequester().getIdLong() : 0L, playingTrack.getPosition() ); musicManager.getScheduler().getQueue().stream() .map(AudioCache::new) .forEach(queue::add); }
@Override public void on(Context context) { GuildAudioController musicManager = this.bot.getGuildsManager().get(context.getEvent().getGuild().getIdLong()); if (musicManager == null || musicManager.getPlayer().getPlayingTrack() == null) { context.reply("No music is playing on this guild! To play a song use `{{prefix}}play`"); return; } AudioTrack currentTrack = musicManager.getPlayer().getPlayingTrack(); context.reply(NOW_PLAYING_FORMAT, currentTrack.getInfo().title, currentTrack.getInfo().author, formatDuration(currentTrack.getPosition()), formatTrackDuration(currentTrack), currentTrack.getInfo().uri); } }
public static void updateSongMessage(User sender, Message message, TextChannel channel) { Track track = FlareBot.instance().getMusicManager().getPlayer(channel.getGuild().getId()).getPlayingTrack(); if (track == null) return; EmbedBuilder eb = MessageUtils.getEmbed(sender) .addField("Current Song", getLink(track), false) .setThumbnail("https://img.youtube.com/vi/" + track.getTrack().getIdentifier() + "/hqdefault.jpg"); if (track.getTrack().getInfo().isStream) eb.addField("Amount Played", "Issa livestream ;)", false); else eb.addField("Amount Played", GeneralUtils.getProgressBar(track), true) .addField("Time", String.format("%s / %s", FormatUtils.formatDuration(track.getTrack().getPosition()), FormatUtils.formatDuration(track.getTrack().getDuration())), false); message.editMessage(eb.build()).queue(); }
eb.setFooter("Source: " + track.getInfo().author, null); double progress = (double)audioPlayer.getPlayingTrack().getPosition()/track.getDuration(); eb.setDescription((audioPlayer.isPaused() ? JMusicBot.PAUSE_EMOJI : JMusicBot.PLAY_EMOJI) + " "+FormatUtil.progressBar(progress) + " `[" + FormatUtil.formatTime(track.getPosition()) + "/" + FormatUtil.formatTime(track.getDuration()) + "]` " + FormatUtil.volumeIcon(audioPlayer.getVolume()));
else eb.addField("Amount Played", GeneralUtils.getProgressBar(track), true) .addField("Time", String.format("%s / %s", FormatUtils.formatDuration(track.getTrack().getPosition()), FormatUtils.formatDuration(track.getTrack().getDuration())), false); ButtonGroup buttonGroup = new ButtonGroup(sender.getIdLong(), ButtonGroupConstants.SONG);