[android-developers] Re: AudioTrack
From the documentation of AudioTrack:
PCM is basically uncompressed audio data. MP3 is compressed audio that's why you hear noise. You have two options for solving that problem:
1. Decode your MP3 stream on the fly and feed it to your AudioTrack
2. Use MediaPlayer instead of AudioTrack
On Wednesday, September 11, 2013 12:35:09 AM UTC-5, Yamusani Vinay wrote:
-- It allows streaming PCM audio buffers to the audio hardware for playback.
PCM is basically uncompressed audio data. MP3 is compressed audio that's why you hear noise. You have two options for solving that problem:
1. Decode your MP3 stream on the fly and feed it to your AudioTrack
2. Use MediaPlayer instead of AudioTrack
On Wednesday, September 11, 2013 12:35:09 AM UTC-5, Yamusani Vinay wrote:
How to play mp3 song using audio track in android.I used following code but i am getting noise...
InputStream in = getResources().openRawResource(R.raw.ding);
try {
ByteArrayOutputStream out = new ByteArrayOutputStream(
in.available()
);
for (int b; (b = in.read()) != -1;) {
out.write(b);
}
Log.d(TAG, "Got the data");
audioData = out.toByteArray();
this.releaseAudioTrack();
this.audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100,
AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_8BIT,
audioData.length, AudioTrack.MODE_STATIC);
Log.d(TAG, "Writing audio data...");
this.audioTrack.write(audioData, 0, audioData.length);
Log.d(TAG, "Starting playback");
audioTrack.play();
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home