How to play two sounds at the same time?
Use media players. Use this code to set up the background music:
MediaPlayer backgroundMediaPlayer = MediaPlayer.create(getApplicationContext(), Uri.parse(PATH_TO_BACKGROUND_MUSIC));mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mediaPlayer) { mediaPlayer.start(); }});
Then replace PATH_TO_BACKGROUND_MUSIC with the background music path.
Then when you want your sound effect to happen, use this code:
MediaPlayer soundEffectMediaPlayer = MediaPlayer.create(getApplicationContext(), Uri.parse(PATH_TO_SOUND_EFFECT)); mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mediaPlayer) { mediaPlayer.start(); } });
Then replace PATH_TO_SOUND_EFFECT with the background music path.
You can learn for about media players here.
Hope this helps!