I am trying to create an audio player object as shown below. Here I get the value for path, but when I inspect for the full, I am getting null, i.e., alertPlayer is returning null for me.
Here is my code,
public class Audio extends Activity {
private static MediaPlayer alertPlayer;
private static void AudioAlert(String alertPath) {
alertPlayer = MediaPlayer.create(Audio.this, Uri.fromfile(new File(path)));
alertPlayer.prepare();
alertPlayer.start();
alertPlayer.stop();
}
}
I am getting the value for this, Uri.fromfile(new File(path)) as it is expected, but MediaPlayer.create(Audio.this, Uri.fromfile(new File(path))); return null.
Any answer for this?
I solved the issue, alertPlayer.prepare() was causing the illegal stateexception. However, now also am not clear why is it happening like that.