2012-01-19 22 views
1

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

回答

1

系統內容提供程序在下載完成後不會立即更新。 嘗試重新啓動您的模擬器或安裝/取消您的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所有。*)

如果你想立即得到的信息,也許你應該更新內容提供者手冊由你自己。

+0

謝謝JohnCookie。我使用默認的MP3播放器立即播放mp3文件,但不顯示標題,藝術家等。我在手機中試過。 (不在模擬器中)。但是我在使用Android瀏覽器下​​載歌曲後嘗試播放歌曲,它顯示標題,藝術家等。 – RiyasMd

+0

它應該是系統數據庫一次不更新細節。系統MediaPlayer應用程序也通過URI獲取信息,請嘗試更新手冊? (我不確定,我只知道我們可以通過contentProvider獲取媒體詳細信息,並且在設備重新啓動或sd卡重新加載時自動更新) – JohnCookie

相關問題