我有以下代码。除了下载的MP3文件在使用默认音乐播放器播放时没有任何属性(元数据),例如艺术家,标题等,一切正常。如果试图直接使用android浏览器从网站上下载相同的mp3文件并使用默认音乐播放器播放,则所有元数据都是完整的(即音乐播放器显示标题,艺术家等)。下载mp3与元数据/属性,如标题,艺术家等
@Override
protected String doInBackground(String... aurl) {
int count;
i = Integer.parseInt(aurl[0]);
try {
sura = "abc.mp3";
String addr = "http://www.xyzabc.com/" + sura;
URL url = new URL(addr);
HttpURLConnection conexion = (HttpURLConnection) url.openConnection();
conexion.setRequestMethod("GET");
conexion.setDoOutput(true);
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
InputStream input = new BufferedInputStream(url.openStream());
File file = new File(rootDir + "/mysite/" + sura);
OutputStream output = new FileOutputStream(file);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1 & run == true) {
total += count;
publishProgress("" + (int) ((total * 100)/lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {
}
return null;
}
谢谢JohnCookie。我使用默认的MP3播放器立即播放mp3文件,但不显示标题,艺术家等。我在手机中试过。 (不在模拟器中)。但是我在使用Android浏览器下载歌曲后尝试播放歌曲,它显示标题,艺术家等。 – RiyasMd
它应该是系统数据库一次不更新细节。系统MediaPlayer应用程序也通过URI获取信息,请尝试更新手册? (我不确定,我只知道我们可以通过contentProvider获取媒体详细信息,并且在设备重新启动或sd卡重新加载时自动更新) – JohnCookie