I'm trying to process the audio buffer in the Android ExoPlayer. In the writeBuffer function of the DefaultAudioSink class, Audio data's coming in a ByteBuffer object. In my case, I want to get the values (as Byte[] if possible) from this ByteBuffer to process the datas before to create a new ByteBuffer and give it to the audioTrack.
I firstly tried to clone the original ByteBuffer in a new ByteBuffer, then send it to the audioTrack (as described in Deep copy duplicate() of Java's ByteBuffer ), to verify it is still working. But the result is an empty buffer for the destination AND the original one (as with this solution)
public static ByteBuffer clone(ByteBuffer original) {
ByteBuffer clone = ByteBuffer.allocate(original.capacity());
original.rewind();//copy from the beginning
clone.put(original);
original.rewind();
clone.flip();
return clone;
}
or something like accelerated audio (if I remove the rewind calls).
A simple
ByteBuffer newBuffer = buffer.duplicate();
has the same behavior.
I'm trying to understand why I can't get a working duplicated audio ByteBuffer, that I can transfer to the AudioTrack and hear the same sound.