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
  • 202,337
  • 40
  • 393
  • 406
Shevach
  • 717
  • 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
  • 484
  • 5
  • 9
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,691
  • 2
  • 21
  • 29