Where do I add another sound ?


Last Updated:

  1. Mikeyfire

    Mikeyfire New Member This Topic's Starter

    Joined:
    Nov 8, 2010
    Messages:
    3
    Likes Received:
    0
    I have the following code that plays a sound file located in my raw folder ...where do I insert the code to add a second sound file ...Thanks



    import java.util.HashMap;

    import android.content.Context;
    import android.media.AudioManager;
    import android.media.SoundPool;

    public class SoundManager {

    private SoundPool mSoundPool;
    private HashMap<Integer, Integer> mSoundPoolMap;
    private AudioManager mAudioManager;
    private Context mContext;

    public SoundManager() {

    }

    public void initSounds(Context theContext) {
    mContext = theContext;
    mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
    mSoundPoolMap = new HashMap<Integer, Integer>();
    mAudioManager = (AudioManager) mContext
    .getSystemService(Context.AUDIO_SERVICE);
    }

    public void addSound(int Index, int SoundID) {
    mSoundPoolMap.put(1, mSoundPool.load(mContext, SoundID, 1));


    }

    public void playSound(int index) {

    int streamVolume = mAudioManager
    .getStreamVolume(AudioManager.STREAM_MUSIC);
    mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume,
    1, 0, 1f);
    }

    public void playLoopedSound(int index) {

    int streamVolume = mAudioManager
    .getStreamVolume(AudioManager.STREAM_MUSIC);
    mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume,
    1, -1, 1f);
    }

    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.question1);
    mSoundManager = new SoundManager();
    mSoundManager.initSounds(getBaseContext());
    mSoundManager.addSound(1, R.raw.magnum);
     

    Advertisement

Share This Page

Loading...