I can receive a byte array from a Socket
. I need to play audio from this byte array - the audio is encoded with AMR 8000Hz.
I found that I can play AMR audio with MediaPlayer
. However, MediaPlayer
can't play music from byte array, and I don't want to write them to file.
Is there a way to play AMR sound from byte array on android?
The Android framework allows you to play back audio data directly from memory using the AudioTrack
class; the drawback is that the audio must already be decoded into PCM data. If you are lucky enough to target Android 4.1, there are new APIs that allow you to decode the data separately so it can be passed to AudioTrack
(see MediaExtractor
and MediaCodec
). However, prior to that there were no exposed APIs for encoding/decoding beyond MediaRecorder
and MediaPlayer
.
If targeting a version of Android prior to 4.1 (which I imagine you probably are) you have two options:
AudioTrack
MediaPlayer
HTH