Reputation: 161
I want to play music from an online mp3 link.
I am reading the music data into a stream and trying to play it using audio track.
But it's giving only noise. I can't hear any music
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 buffers I can play in MediaPlayer, but I could not play in audiotrack.
What could I be doing wrong?
Upvotes: 2
Views: 5575
Reputation: 4882
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 ).
Upvotes: 3