How do I play multiple instances of the same music placed in the code below? Also if I am playing 2 different sounds at once, where do I place that code?
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 addSounds(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);
}
}
My main method is as follows: I have called this in the onCreate method
m=new SoundManager();
m.initSounds(getBaseContext());
m.addSounds(1, R.raw.sound);
Button button=(Button)findViewById(R.id.button11);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
m.playSound(1);
}
});
}
example code:
Music music = MusicFactory.createMusicFromAsset(pMusicManager, pContext, pAssetPath);
Music music2 = MusicFactory.createMusicFromAsset(pMusicManager, pContext, pAssetPath);
music.play;
music2.play;