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下載它時,你會以某種方式檢索它。 –