0

How to protect MediaPlayer function from error I mean when I click a button to play sound (multiple times) after about 5th click application forces close. I have tried to do something like counter and after 2nd click it was stopping, preparing and releasing MP but it's not working

1
  • If you show your code, it will be easier to help.
    – MByD
    Mar 18, 2012 at 11:10

1 Answer 1

0

If i were you, i defined MediaPlayer and counter static like as follow:

public class Global {
    public static int counter = 0;

    public static MediaPlayer MP;
}

And use them where i need (e.g in an OnClickListener) as follow:

Global.counter ++;
if (Global.counter >= 2) {
    // do something
} else {
    // do another thing
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.