Code example for SoundPool

Methods: loadplay

0
    blockExplosion = blowUp.load(GameData.leContext, R.raw.blow_up, 1);
  } 
 
  public boolean play(Context context, int resId)
  { 
    SoundPool pool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
    int sound = pool.load(context, resId, 0);
    if (sound != 0)
      pool.play(sound, 1, 1, 0, 0, 1);
    else 
      return false; 
    return true; 
  } 
 
  public void startMusic(GameData gamedata)
  { 
    if (gamedata.getPlayMusic())
    { 
      mediaplayer = MediaPlayer.create(GameData.leContext, R.raw.random_song);
      mediaplayer.start();
      mediaplayer.setLooping(true);