I have used JLayer library to decode the mp3 file . A function which 
returns byte[] by decoding file picked from sdcard.
so means i get bytes(array of bytes from that decoder function).
here is some code i m using.

>
>  int minSize =AudioTrack.getMinBufferSize( 8000, 
> AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT ); 
>        
> mySong = new AudioTrack( AudioManager.STREAM_MUSIC, 
> 8000,AudioFormat.CHANNEL_CONFIGURATION_STEREO, 
> AudioFormat.ENCODING_PCM_16BIT, minSize, AudioTrack.MODE_STREAM);


Eg:

> buffer = decode(Environment.getExternalStorageDirectory()+"/cm.mp3", 
> 0,1500);
> mySong.play();
> mySong.write(buffer, 0, buffer.length);




and code for decode is:

 public static byte[] decode(String path, int startMs, int maxMs)  throws 
> IOException, DecoderException 
> {
> ByteArrayOutputStream outStream = new ByteArrayOutputStream(1024);
> float totalMs = 0;
> boolean seeking = true;
> File file = new File(path);
> InputStream inputStream = new BufferedInputStream(new 
> FileInputStream(file), 8 * 1024);
> try
> {
>     Bitstream bitstream = new Bitstream(inputStream);
>     Decoder decoder = new Decoder();
>     boolean done = false;
>     while (! done)
>     {
>       javazoom.jl.decoder.Header frameHeader = bitstream.readFrame();
>       if (frameHeader == null)
>         done = true;
>       else
>       {
>         totalMs += frameHeader.ms_per_frame();
>         if (totalMs >= startMs)
>          seeking = false;
>         if (! seeking)
>         {
>           SampleBuffer output = (SampleBuffer) 
> decoder.decodeFrame(frameHeader, bitstream);
>                      if (output.getSampleFrequency() != 44100 || 
> output.getChannelCount() != 2)
>                 throw new DecoderException("mono or non-44100 MP3 not 
> supported", null);
>           short[] pcm = output.getBuffer();
>           for (short s : pcm)
>           {
>             outStream.write(s & 0xff);
>             outStream.write((s >> 8 ) & 0xff);
>           }
>         }
>         if (totalMs >= (startMs + maxMs))
>           done = true;
>       }
>       bitstream.closeFrame();
>     }
> return outStream.toByteArray();
>    }
>    catch (BitstreamException e)
>    {
>     throw new IOException("Bitstream error: " + e);
>    } 
>    catch (DecoderException e) 
>    {
>    Log.w("error is:", "Decoder error", e);
>        }
> return null;
> }


if i give maxMs(maximum number of seconds >15) it takes way to long. 
       and for song of 28-30 seconds it takes more than 1 min to load and 
decode. is there any other library or way.
I just want to play large mp3 files but importantly want to modify the 
pitch. means user can change the speed 1x ,2x,3x etc.
SoundPool and AudioTrack do this. SoundPool cant play  large files.

-- 
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

Reply via email to