Take the 2-minute tour ×

I want to use SoundPool class to create Playback speed effects. To play sound fastly or slowly (1x,0.5x,2x etc). But the problem is soundpool handles only small files. When i give a large file. It doesn't play anything. I was wondering if it would be possible to load stream of music (some bytes of my large audio file) and play it via soundpool. any idea.??

Here is my code for soundPool to play song

AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = streamVolumeCurrent / streamVolumeMax;  
soundID = soundPool.load(Environment.getExternalStorageDirectory()+"/cm.mp3", 1);
soundPool.play(soundID, volume, volume, 1, 0, 1.0f);

I found JetPlayer and AudioTrack classes, but i m not finding any good tutorials to handle this.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You will need to check file is loaded successfully before playing it using SoundPool.setOnLoadCompleteListener

public void loadSound (String strSound, int stream) {
     boolean loaded = false;
     mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
            public void onLoadComplete(SoundPool soundPool, int sampleId,
                    int status) {
                loaded = true;
    try {
          stream= mSoundPool.load(aMan.openFd(strSound), 1);
        } catch (IOException e) {
        // TODO Auto-generated catch block
   // Is the sound loaded already?
   if (loaded) {
     mSoundPool.play(stream, streamVolume, streamVolume, 1, LOOP_1_TIME, 1f);

where aMan is

AssetFileDescriptor aMan =  getAssets();
share|improve this answer
are you sure it ll work to play large sound files? and what is aMan? –  Bhupinder Feb 8 '13 at 7:29
@Bhupinder No it will not play large file because SoundPool is basicaly use to play click sound or some small sound. But still it will load that large file and play some starting bits of that file. And for 'aMan' I updated my answer. I hope this will help you –  Chirag Patel Feb 8 '13 at 12:35

Your Answer


