我在 Android 上播放外部 MP3 文件时遇到问题。我正在使用以下代码:
MediaPlayer player = new MediaPlayer();
try {
BufferedInputStream bis = new BufferedInputStream(new java.net.URL(url).openStream());
FileOutputStream fos = new FileOutputStream(Environment.getExternalStorageDirectory().getPath() + "/forvo_temp.mp3");
BufferedOutputStream bos = new BufferedOutputStream(fos,1024);
byte [] data = new byte[1024];
int x=0;
while((x=bis.read(data,0,1024))>=0){
bos.write(data,0,x);
}
player.reset();
player.start();
} catch (Exception e) {
e.printStackTrace();
}
url
是外部文件所在的字符串。我确实拥有 SD 卡 ( WRITE_EXTERNAL_STORAGE
) 的写入权限。
在调试中,我看到:
E MediaPlayer start called in state 1
E MediaPlayer error (-38, 0)
E MediaPlayer Error (-38,0)
问题可能是什么?