com.sedmelluq.discord.lavaplayer.tools.io.MessageInput Java Examples

The following examples show how to use com.sedmelluq.discord.lavaplayer.tools.io.MessageInput. 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: RequestUtils.java    From andesite-node with MIT License 6 votes vote down vote up
/**
 * Decodes an audio track from it's base64 representation.
 *
 * @param playerManager Player manager used for decoding (must have the source manager enabled).
 * @param base64        Base64 encoded track.
 *
 * @return The decoded track.
 */
@Nullable
@CheckReturnValue
public static AudioTrack decodeTrack(@Nonnull AudioPlayerManager playerManager, @Nonnull String base64) {
    try {
        var v = playerManager.decodeTrack(new MessageInput(new ByteArrayInputStream(
            Base64.getDecoder().decode(base64)
        )));
        return v == null ? null : v.decodedTrack;
    } catch(IOException e) {
        throw new AssertionError(e);
    }
}
 
Example #2
Source File: DefaultAudioPlayerManager.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@Override
public DecodedTrackHolder decodeTrack(MessageInput stream) throws IOException {
  DataInput input = stream.nextMessage();
  if (input == null) {
    return null;
  }

  int version = (stream.getMessageFlags() & TRACK_INFO_VERSIONED) != 0 ? (input.readByte() & 0xFF) : 1;

  AudioTrackInfo trackInfo = new AudioTrackInfo(input.readUTF(), input.readUTF(), input.readLong(), input.readUTF(),
      input.readBoolean(), version >= 2 ? DataFormatTools.readNullableText(input) : null);
  AudioTrack track = decodeTrackDetails(trackInfo, input);
  long position = input.readLong();

  if (track != null) {
    track.setPosition(position);
  }

  stream.skipRemainingBytes();

  return new DecodedTrackHolder(track);
}
 
Example #3
Source File: MusicController.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@BotCommandHandler
private void deserialize(Message message, String content) throws IOException {
  outputChannel.set((TextChannel) message.getChannel());
  connectToFirstVoiceChannel(guild.getAudioManager());

  byte[] bytes = Base64.decode(content);

  MessageInput inputStream = new MessageInput(new ByteArrayInputStream(bytes));
  DecodedTrackHolder holder;

  while ((holder = manager.decodeTrack(inputStream)) != null) {
    if (holder.decodedTrack != null) {
      scheduler.addToQueue(holder.decodedTrack);
    }
  }
}
 
Example #4
Source File: JbAudioPlayerManagerImpl.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AudioTrack decodeTrack(byte[] data) {
    if (ArrayUtils.isEmpty(data)) {
        return null;
    }
    try (ByteArrayInputStream stream = new ByteArrayInputStream(data)) {
        DecodedTrackHolder holder = decodeTrack(new MessageInput(stream));
        return holder != null && holder.decodedTrack != null ? holder.decodedTrack : null;
    } catch (IOException e) {
        log.warn("Could not decode track");
    }
    return null;
}
 
Example #5
Source File: LavalinkTrackLoader.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
private static AudioTrack decode(AudioPlayerManager manager, String track) {
    try {
        return manager.decodeTrack(new MessageInput(new ByteArrayInputStream(
                Base64.getDecoder().decode(track)
        ))).decodedTrack;
    } catch (Exception e) {
        throw new IllegalArgumentException("Failed to decode track", e);
    }
}
 
Example #6
Source File: LavalinkUtil.java    From Lavalink-Client with MIT License 4 votes vote down vote up
/**
 * @param message the unencoded audio track
 * @return the AudioTrack
 * @throws IOException if there is an IO problem
 */
@SuppressWarnings("WeakerAccess")
public static AudioTrack toAudioTrack(byte[] message) throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(message);
    return PLAYER_MANAGER.decodeTrack(new MessageInput(bais)).decodedTrack;
}
 
Example #7
Source File: Util.java    From Lavalink with MIT License 4 votes vote down vote up
public static AudioTrack toAudioTrack(AudioPlayerManager audioPlayerManager, String message) throws IOException {
    byte[] b64 = Base64.decodeBase64(message);
    ByteArrayInputStream bais = new ByteArrayInputStream(b64);
    return audioPlayerManager.decodeTrack(new MessageInput(bais)).decodedTrack;
}
 
Example #8
Source File: AudioPlayerManager.java    From lavaplayer with Apache License 2.0 2 votes vote down vote up
/**
 * Decode a track from an input stream. Null returns value indicates reaching the position where the decoder had
 * called MessageOutput#finish().
 *
 * @param stream The message stream to read it from.
 * @return Holder containing the track if it was successfully decoded.
 * @throws IOException On IO error.
 */
DecodedTrackHolder decodeTrack(MessageInput stream) throws IOException;