Java Code Examples for com.sedmelluq.discord.lavaplayer.track.AudioTrack#getUserData()

The following examples show how to use com.sedmelluq.discord.lavaplayer.track.AudioTrack#getUserData() . 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: TrackScheduler.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onTrackStart(AudioPlayer player, AudioTrack track) {
    final TrackUserData data = track.getUserData(TrackUserData.class);

    // If the track was a skipped track or we announce tracks
    if (data.getWasFromSkip() || this.guildMusicManager.isAnnounceTracks()) {
        // Reset the was from skip status
        data.setWasFromSkip(false);

        final EmbedBuilder message = AudioTrackKt.toEmbed(
            track,
            this.guildMusicManager,
            getInstance().getShardManager(),
            false
        );

        sendEmbed(this.guildMusicManager.getLatestChannel(), message);
    }
}
 
Example 2
Source File: TrackScheduler.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
private TrackUserData createNewTrackData(AudioTrack track, boolean wasFromSkip) {
    final TrackUserData oldData = track.getUserData(TrackUserData.class);
    final TrackUserData newData;

    // If we did not have old data (unlikely) we will create it
    if (oldData == null) {
        newData = new TrackUserData(0L);
    } else {
        newData = oldData.copy(oldData.getRequester());
    }

    // Set the was from skip status on the track
    newData.setWasFromSkip(wasFromSkip);

    return newData;
}
 
Example 3
Source File: LavalinkPlayer.java    From Lavalink-Client with MIT License 5 votes vote down vote up
@Override
public void playTrack(AudioTrack track) {
    try {
        position = track.getPosition();
        TrackData trackData = track.getUserData(TrackData.class);

        JSONObject json = new JSONObject();
        json.put("op", "play");
        json.put("guildId", link.getGuildId());
        json.put("track", LavalinkUtil.toMessage(track));
        json.put("startTime", position);
        if (trackData != null) {
            json.put("startTime", trackData.startPos);
            json.put("endTime", trackData.endPos);
        }
        json.put("pause", paused);
        json.put("volume", volume);
        //noinspection ConstantConditions
        link.getNode(true).send(json.toString());

        updateTime = System.currentTimeMillis();
        this.track = track;
        emitEvent(new TrackStartEvent(this, track));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 4
Source File: LavalinkUtil.java    From Lavalink-Client with MIT License 5 votes vote down vote up
/**
 *
 * @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 5
Source File: TrackData.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
public static TrackData get(AudioTrack track) {
    TrackData trackData = track.getUserData(TrackData.class);
    if (trackData == null) {
        track.setUserData(trackData = new TrackData());
    }
    return trackData;
}
 
Example 6
Source File: AudioUtils.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
public static String getQueueList(ConcurrentLinkedDeque<AudioTrack> queue) {
    StringBuilder sb = new StringBuilder();
    int n = 1;
    for (AudioTrack audioTrack : queue) {
        long aDuration = audioTrack.getDuration();
        String duration = String.format("%02d:%02d",
                TimeUnit.MILLISECONDS.toMinutes(aDuration),
                TimeUnit.MILLISECONDS.toSeconds(aDuration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(aDuration))
        );

        User dj = audioTrack.getUserData() != null ? MantaroBot.getInstance().getShardManager()
                .getUserById(String.valueOf(audioTrack.getUserData())) : null;

        sb.append("**")
                .append(n)
                .append(". [")
                .append(StringUtils.limit(audioTrack.getInfo().title, 30))
                .append("](")
                .append(audioTrack.getInfo().uri)
                .append(")** (")
                .append(duration)
                .append(")")
                .append(dj != null ? " **[" + dj.getName() + "]**" : "")
                .append("\n");
        n++;
    }
    return sb.toString();
}