I have a method in my class called play, and I want to play, which plays an audio file. Which file is played depends on the value of the current audio index. In principle, there is such a switch:
int rId; switch (audioIndex){ case 0: rId = R.raw.e0.wav; break; case 1: rId = R.raw.e1.wav; break; default: rId = R.raw.error.wav; break; }
After switching, I want to check if rId is valid before passing it to MediaPlayer.create (this, rId). It seems that create does not throw an exception if the identifier does not exist or cannot be opened. So what should I check before passing it on?
How to gracefully handle this? So far, I just assumed that rId will always be correct, but I would like to check to make sure.
source share