1
我试图从服务器上下载mp3文件。 我成功制作了它,我可以播放该文件,但没有缩略图和文件信息,例如艺术家和专辑名称。Android AsyncTask下载.mp3文件 - 信息和缩略图
当我直接从chrome下载文件时,我上面提到的信息会被下载。 任何想法如何让它工作?
这里是我的代码:
URL url = new URL(urlDwn+urlVid);
HttpURLConnection connection =(HttpURLConnection) url.openConnection();
connection.connect();
//file length
int lengthOfFile = connection.getContentLength();
//intput - read file
InputStream inputStream = new BufferedInputStream(url.openStream(), 8192);
//output - write file
if(true) {
System.out.println("Downloading");
OutputStream outputStream = new FileOutputStream(root+"/"+fileName);
System.out.println(root+"/"+fileName);
byte data[] = new byte[1024];
long total = 0;
while ((count = inputStream.read(data)) != -1) {
total += count;
//progress
publishProgress((int) ((total * 100)/lengthOfFile));
//writing to file
outputStream.write(data,0, count);
}
outputStream.flush();
outputStream.close();
inputStream.close();
可能问题是您检索缩略图和信息的方式? –
我如何检索它? –
当你通过chrome下载它时,你会以某种方式检索它。 –