我有以下代碼。除了下載的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