I'm trying to play the sounds according to what's called on the arraylist but the sounds are playing randomly and it seems like the sounds are overlapping. what is wrong with my code and what code should i use or add? can anyone help me?
here is my code:
package com.example.sample;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
MediaPlayer mp = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.play);
final Button buttonPlay = (Button) findViewById(R.id.idPlay);
buttonPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
managerOfSound();
} // END onClick()
}); // END buttonHello
} // END onCreate()
protected void managerOfSound() {
if (mp != null) {
mp.reset();
mp.release();
}
for (int i = 0; i < tempq.size(); i++){
if (tempq.contains("a1")){
mp = MediaPlayer.create(this, R.raw.a1);
mp.start();
}else if (tempq.contains("b1")){
mp = MediaPlayer.create(this, R.raw.b1);
mp.start();
}else if (tempq.contains("c1")){
mp = MediaPlayer.create(this, R.raw.c1);
mp.start();
}else if (tempq.contains("d1")){
mp = MediaPlayer.create(this, R.raw.d1);
mp.start();
}else if (tempq.contains("e1")){
mp = MediaPlayer.create(this, R.raw.e1);
mp.start();
}else if (tempq.contains("f1")){
mp = MediaPlayer.create(this, R.raw.f1);
mp.start();
}else if (tempq.contains("g1")){
mp = MediaPlayer.create(this, R.raw.g1);
mp.start();
}else if (tempq.contains("h1")){
mp = MediaPlayer.create(this, R.raw.h1);
mp.start();
}else if (tempq.contains("i1")){
mp = MediaPlayer.create(this, R.raw.i1);
mp.start();
}else if (tempq.contains("j1")){
mp = MediaPlayer.create(this, R.raw.j1);
mp.start();
}else if (tempq.contains("k1")){
mp = MediaPlayer.create(this, R.raw.k1);
mp.start();
}else if (tempq.contains("l1")){
mp = MediaPlayer.create(this, R.raw.l1);
mp.start();
}else if (tempq.contains("m1")){
mp = MediaPlayer.create(this, R.raw.m1);
mp.start();
}else if (tempq.contains("a4")){
mp = MediaPlayer.create(this, R.raw.a4);
mp.start();
}else if (tempq.contains("b4")){
mp = MediaPlayer.create(this, R.raw.b4);
mp.start();
}else if (tempq.contains("c4")){
mp = MediaPlayer.create(this, R.raw.c4);
mp.start();
}else if (tempq.contains("d4")){
mp = MediaPlayer.create(this, R.raw.d4);
mp.start();
}else if (tempq.contains("e4")){
mp = MediaPlayer.create(this, R.raw.e4);
mp.start();
}else if (tempq.contains("f4")){
mp = MediaPlayer.create(this, R.raw.f4);
mp.start();
}else if (tempq.contains("g4")){
mp = MediaPlayer.create(this, R.raw.g4);
mp.start();
}else if (tempq.contains("h4")){
mp = MediaPlayer.create(this, R.raw.h4);
mp.start();
}else if (tempq.contains("i4")){
mp = MediaPlayer.create(this, R.raw.i4);
mp.start();
}else if (tempq.contains("j4")){
mp = MediaPlayer.create(this, R.raw.j4);
mp.start();
}else if (tempq.contains("k4")){
mp = MediaPlayer.create(this, R.raw.k4);
mp.start();
}else if (tempq.contains("l4")){
mp = MediaPlayer.create(this, R.raw.l4);
mp.start();
}else if (tempq.contains("m4")){
mp = MediaPlayer.create(this, R.raw.m4);
mp.start();
}
}
}
}