4

I was working on a simple bubblewrap app in order to learn the android framework, and was wondering how I could play the 'pop' sound clip every time the user touches a bubble.

Thanks in advance

iman453
  • 9,105
  • 16
  • 54
  • 70

3 Answers3

4

Use a SoundPool combined with an OnTouchListener. In your onTouch(..) method you would simply do a SoundPool.play(YOURAUDIOFILE, 1, 1, 1, 0, 1);

Gl hf

Cpt.Ohlund
  • 2,589
  • 1
  • 20
  • 15
3

I know it's a cop out to just link to someone else's explanation, but I had to do the exact same thing, and here's the tutorial I used: http://www.droidnova.com/creating-sound-effects-in-android-part-2,695.html

Neil Traft
  • 18,367
  • 15
  • 63
  • 70
0

You Can use MedaiPlayer as following inside onTouchListener:

  mPlayer = new MediaPlayer();
            mPlayer.setAudioStreamType(AudioManager.STREAM_RING);

            try {
                mPlayer.setDataSource(mContext,
                        Uri.parse("android.resource://" + mContext.getPackageName() + "/" + R.raw.YourFileName));
                mPlayer.prepare();
            } catch (IOException e) {
                Log.e(LOG_TAG, "Could not setup media player for ringtone");
                mPlayer = null;
                return;
            }
            mPlayer.setLooping(false);
            mPlayer.start();
zMabrook
  • 932
  • 7
  • 9