Search code examples
androidsoundpool

Android soundPool supported Extension?


I wrote this code in the onCreate() method, but nothing was played !

   SoundPool mSound = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
   AudioManager mAudioManager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);          

   int soundID = mSound.load(this, R.raw.sound1, 1);

   int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); 
   mSound.play(soundID, streamVolume, streamVolume, 1, 0, 1f);

Question #1 : Is there a problem with my code ? Did I do it wrongly ?

If No,

Question #2 : My sound is .amr file. Is it supported by SoundPool ? What are the supported types ?


Solution

  • Everything is fine, but you should wait some time after loading and before play. It takes some time to load. You can check if the sound is loaded with the help of "OnLoadCompleteListener".