我正在尝试使用此代码,我从按钮调用但它不起作用,当我看到LogCat窗口时,我发现Media Player在状态0中调用,错误(-38,0)
public void audioPlayer(String path, String fileName){
//set up MediaPlayer
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(HeyActivity.this, Uri.parse(path+"/"+fileName));
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
System.out.print("hey");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
}
答案 0 :(得分:2)
尝试设置OnPreparedListener并在其中调用start方法。像这样:
MediaPlayer mp = new MediaPlayer();
mp.setOnPreparedListener( new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mp.start();
}
};
);
答案 1 :(得分:1)
我终于通过在支持音频的模拟器上运行来解决问题!!
简直不敢相信!
窗口> AVD Manager>编辑你的AVD(我创建了一个新的安全端,因为我从快照运行)>硬件>新>音频播放支持