tags:

views:

270

answers:

1

Hi All,

I want to play music from online mp3 link.

I am reading the music data into a stream and trying to play it using audio track.

But itz giving only noise.No music i could listen.

This is my code.

int intSize = android.media.AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT);

AudioTrack oTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, intSize, AudioTrack.MODE_STREAM);

oTrack.play(); oTrack.write(buffer, 0, buffer.length);

here buffer is the audio data i am reading into.

Same buffer I can play in MediaPlayer,,,But i could not play in audiotrack..

Please tell me the solution.

It is urgent.

Thanks Kavitha

+1  A: 

Apparently AudioTrack only plays PCM audio, so either you will have to find a way to decode the MP3 into PCM yourself, or use MediaPlayer instead which can do the decoding for you (according to http://developer.android.com/guide/topics/media/index.html ).

Luke Dunstan