But how to decode mp3 file to pcm programatically
On Wed, Sep 11, 2013 at 5:53 PM, Nobu Games <[email protected]>wrote: > From the documentation of > AudioTrack<http://developer.android.com/reference/android/media/AudioTrack.html> > : > > 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<http://developer.android.com/reference/android/media/MediaPlayer.html>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 [email protected] > To unsubscribe from this group, send email to > [email protected] > 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 a topic in the > Google Groups "Android Developers" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/android-developers/meR8tp4GV4U/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] 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 [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

