I have a heapbytebuffer in a variable "myByteBuffer" that represents an audio wav that I want to playback. I see that AudioInputStream is a way to play files using AudioSystem.getAudioInputStream(soundFile). Since it accepts a "File", how can I convert the heapbytebuffer I have to a "File"?
Asked
Active
Viewed 203 times
1 Answers
1
Don't use the File
overload unless you have (or want to save) a physical file. Just take your data and wrap it in an InputStream
:
AudioSystem.getAudioInputStream(new ByteArrayInputStream(myByteBuffer.array()))
This assumes you're using the full buffer. If not, you can slice out the part you're using as necessary. See here for details.