Shevach
Shevach

Reputation: 737

Play audio from buffer

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.

Upvotes: 2

Views: 8482

Answers (2)

Greg Hensley
Greg Hensley

Reputation: 624

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[].

Upvotes: 6

pkk
pkk

Reputation: 3691

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.

Upvotes: 1

Related Questions