我想創建一個音頻播放器對象,如下所示。在這裏,我得到了路徑的值,但是當我檢查完整時,我得到空值,即alertPlayer爲我返回null。媒體播放器對象返回null
這裏是我的代碼,
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();
}
}
我正在爲此,Uri.fromfile(新文件(路徑)),因爲它的預期,但MediaPlayer.create(Audio.this,開放的價值。 fromfile(new File(path)));返回null。
對此的任何回答?
null問題我解決了,這是我的網址下載音頻時出現的問題。但是,現在我得到一個新的異常,即IllegalStateException,當我做alertPlayer.prepare();你能預測這個嗎? – tejas