I need help with playing multiple audio tracks at the same time in Android
.
I am supposed to play three audio tracks at the exact same
hi try below code it will work it the song wont stop you just need to select the song from spinner and click on start button, then select next song from spinner and click start it will work.
public class MainActivity extends AppCompatActivity {
Spinner sp;
Button bstart;
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp=(Spinner)findViewById(R.id.sp);
String [] mys={"demo","democheap","demorehana"};
ArrayAdapter data=new ArrayAdapter(this,R.layout.support_simple_spinner_dropdown_item,mys);
sp.setAdapter(data);
}
public void code(View v)
{
if(sp.getSelectedItem().toString().equals("demo"))
{
mp=MediaPlayer.create(this,R.raw.demo);
}
else if(sp.getSelectedItem().toString().equals("democheap"))
{
mp=MediaPlayer.create(this,R.raw.democheap);
}
else if(sp.getSelectedItem().toString().equals("demorehana"))
{
mp=MediaPlayer.create(this,R.raw.demorehana);
}
if(v.getId()==R.id.bstart)
{
mp.start();
}
}
}