Android Question.
public void myClickHandler(View v) {
switch (v.getId())
{ //opens switch test
case R.id.SoundOneButton:
asoundfilenumber=0x7f040001;
break;
case R.id.SoundTwoButton:
asoundfilenumber=0x7f040002;
break;
case R.id.SoundThreeButton:
asoundfilenumber=0x7f040003;
break;
case R.id.PlayButton:
while (count <=repeat) //opens while loop in case r.id.PlayButton
{
MediaPlayer mp = MediaPlayer.create(getBaseContext(), asoundfilenumber);
mp.start();
mp.setOnCompletionListener(new OnCompletionListener()//listens for player to finish then releases player
{
@Override
public void onCompletion(final MediaPlayer mp)
{
mp.release();
}
});
count++;
}//closes while loop in case r.id.PlayButton
count=0;//resets count to 0 after all repeat play is finished
break;
}//closes switch test
}//closes onClick
My problem is when MediaPlayer repeats more than two or three times or finishes repeating then is asked to repeat again, the activity fails to respond and I can either force close or wait. If I select wait, the application keeps working.
The audio files are Ogg and 19K in size. I'm trying to have them play between 1 and 10 times.
Is my problem due to not resetting the mediaplayer before each repeat? I looked at SoundPool and AudioTrack but it seemed that MediaPlayer was more suited.
Thank you for your time and help.