下载带有元数据/属性(例如标题、艺术家等)的 mp3
我有以下代码。一切工作正常,除了当我使用默认音乐播放器播放时,下载的 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;
}
I have the following code. Everything works fine except that the downloded MP3 file does not have any property (metadata) such as Artist, title and etc when I play using the default music player. If tried to download the same mp3 file from the site directly using android browser and play using the default music player, all the metatdata are intact (ie. music player display title, artist and etc).
@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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下载完成后,系统内容提供程序不会立即更新。
尝试重新启动模拟器或安装/卸载 SD 卡,查看内容提供商是否更新。
uri 为
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
,您可以通过查询MediaStore.Audio.Media.DATA、MediaStore.Audio.Media.TITLE 获取详细信息,
和其他(全部在 MediaStore.Audio.Media.* 中)MediaStore.Audio.Media.COMPOSER、MediaStore.Audio.Media.ALBUM、
MediaStore.Audio.Media.ARTIST
如果您想立即获取信息,也许您应该自己更新 Content Provider 手册。
The System content provider didn't update as soon as your downloading complete.
Try restart your emulator or install/unstall your sd card, see if the content provider updates.
The uri is
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
and you can get details by queryMediaStore.Audio.Media.DATA, MediaStore.Audio.Media.TITLE,
and others (All in MediaStore.Audio.Media.*)MediaStore.Audio.Media.COMPOSER, MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.ARTIST
If you want to get the information immediately, maybe you should update the Content Provider manual by yourself.