I am having an issue where occasionally the MediaPlayer.create method will return null, even though the audio file is definitely there. In fact, if I put the call to create into a while loop, the media player will eventually be created successfully. This only seems to happen on my phone (HTC Hero running 2.1) and never in the emulator.
Is this just an issue with the phone? Or is there a different way I should be playing these audio files?
Note that I want to be loading them dynamically which is get I am making the call to getIndentifer. If there is a better way of playing these dynamically please let me know.
public void playAudio(String audioFile){
//instance variable of type MediaPlayer
_player = null;
while(_player == null){
_player = MediaPlayer.create(_context, getResources().getIdentifier(audioFile, "raw", _context.getPackageName()));
}
_player.start();
}
Thanks.