0

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"?

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
Rolando
  • 58,640
  • 98
  • 266
  • 407

1 Answers1

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.

Community
  • 1
  • 1
shmosel
  • 49,289
  • 6
  • 73
  • 138