2017-07-06 4 views
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(); 
+0

サムネイルと情報を取得するのに問題がありますか? –

+0

どのように取得できますか? –

+0

あなたはそれをChrome経由でダウンロードするときに何らかの方法で取得します。 –

答えて

1

私はそれを解決しよう!

サムネイルとmp3タグ(アーティストなど)が適切にダウンロードされたようです。問題はファイルマネージャ自体(あるいはAndroidシステム)にあったので、私がデバイスを再起動すると、それ自体が表示されました!

EDIT

リブートする必要はありません。以下の行をonPostExecuteメソッドに追加するだけで、システムに新しいファイルが追加されたことが通知されます。

Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); 
intent.setData(Uri.fromFile(file)); 
sendBroadcast(intent); 
関連する問題