2

I want to play audio from a buffer. Something like using the AudioRecord to record the audio into buffer and play it from the buffer.

Is there a way of doing it? In the MediaPlayer there is no such option.

Mat
  • 195,986
  • 40
  • 382
  • 396
Shevach
  • 669
  • 9
  • 25

2 Answers2

6

You can do this with the AudioTrack class. Its interface is very similar to that of AudioRecord, except that the AudioTrack can only use buffers of type byte[] and short[].

Greg Hensley
  • 334
  • 4
  • 8
1

You may use temp file as described in solution here:

Android - Playing mp3 from byte[]

or if your file comes from the internet (referenced by URL for example), you may use:

setDataSource(Context context, Uri uri)

presented in the same question.

Community
  • 1
  • 1
pkk
  • 3,651
  • 2
  • 19
  • 29