• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Websocket Streaming

By using native player, we can play mp3 container audio through websocket stream, But we got exact 30 Sec latency, On player initialize we hear the audio after 30 sec. How can we reduce these latency. Is that value configurable somewhere in android library.
Actually I am playing raw pcm data using AudioTrack through websocket so it is giving me clean audio quality ok so when I am receiving some encoder contained data through websocket then my AudioTrack play audio but it has 30 sec latency so the data receiving at websocket is of aac encoded and mp3 container using ffmpeg this type of data AudioTrack can decode but it takes 30sec approx and then play so we can say that latency of 30 sec we need to reduce latency as pcm data run as it is on Android device which has no latency ....

Here is my code
on oncreate method

bufferSize = AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_MP3);
mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_MP3, bufferSize, AudioTrack.MODE_STREAM);
mAudioTrack.play();


in websocket override method.....

@override
public void onBinaryReceived(byte[] data) {
Log.e("onBinaryReceived",""+data);
try{
/* dataa = createMediaSourceFromByteArray(data);
Log.e("data",""+dataa);
runOnUiThread(new Runnable() {
@override
public void run() {
initplayerExo(dataa);
}
});*/
mAudioTrack.write(data, 0, data.length);
 
Back
Top Bottom