我有以下代码。一切正常,除了当我使用默认音乐播放器播放时下载的 MP3 文件没有任何属性(元数据),如艺术家、标题等。如果尝试直接使用 Android 浏览器从站点下载相同的 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;
}
最佳答案
系统内容提供程序没有在您下载完成后立即更新。 尝试重新启动您的模拟器或安装/卸载您的 SD 卡,查看内容提供商是否更新。
uri是MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
,你可以通过查询MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.COMPOSER, MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.ARTIST
和其他(全部在 MediaStore.Audio.Media.* 中)
如果您想立即获取信息,也许您应该自行更新 Content Provider 手册。
关于java - 下载带有元数据/属性(如标题、艺术家等)的 mp3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8921953/