Friday, 30 August 2013

Check and see if a sound is playing, wait for it to finish and then play another [android]

Check and see if a sound is playing, wait for it to finish and then play
another [android]

What i am trying to acomplish is for me to click on a button and then play
a sound based on a substring.
This is my current code for pressing the button :
display.setText("start");
thefull = thef.getText().toString();
for(int a=0;a<thefull.length();a++)
{
letter=thefull.substring(a,a+1);
if(letter=="m")
{
oursong = MediaPlayer.create(MainActivity.this, R.raw.m);
oursong.start();
while(oursong.isPlaying())
{
display.setText("start");
}
oursong.release();
}
else if(letter=="a")
{
oursong = MediaPlayer.create(MainActivity.this, R.raw.a);
oursong.start();
while(oursong.isPlaying())
{
display.setText("start");
}
oursong.release();
}
display.setText("done");
but for some reason when i click my button no sound is played. I am also
new to android and java programming, so am i going right about doing this?
Because what i really want is for the program to keep checking if a sound
is playing(in this case "oursound) when the button is clicked and if the
sound is playing i want the program to wait for it to finish to start
another sound right after it. But for now my code doesn´t play any sounds
Thanks in advanced for the help

No comments:

Post a Comment