2017-01-24 179 views
0

Hy。我正在開發一個Android應用程序,我正在從服務器下載視頻。我沒有問題同時下載多個視頻並將其保存在SD卡中。我正在使用DownloadManager類進行下載。我可以在狀態欄中看到下載圖標,並在通知區域下載進度,並由DownloadManger自己管理。我有一個單獨的標籤名稱下載,我使用的是一個列表視圖來顯示以前下載的視頻,但現在我也必須顯示當前下載的視頻進度條。我的問題是 1 - 如何讓當前正在下載的視頻以列表視圖顯示 2 - 如何維護所有視頻的進度條。用進度條下載多個視頻

這是一個圖像連接到顯示我想要實現我當前的代碼

String urlDownload = "https://dl.dropbox.com/s/ex4clsfmiu142dy/test.zip?token_hash=AAGD-XcBL8C3flflkmxjbzdr7_2W_i6CZ_3rM5zQpUCYaw&dl=1"; 
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(urlDownload)); 

    request.setDescription("Testando"); 
    request.setTitle("Download"); 
    request.allowScanningByMediaScanner(); 
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "teste.zip"); 

    final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); 

    final long downloadId = manager.enqueue(request); 

    final ProgressBar mProgressBar = (ProgressBar) findViewById(R.id.progressBar1); 

    new Thread(new Runnable() { 

     @Override 
     public void run() { 

      boolean downloading = true; 

      while (downloading) { 

       DownloadManager.Query q = new DownloadManager.Query(); 
       q.setFilterById(downloadId); 

       Cursor cursor = manager.query(q); 
       cursor.moveToFirst(); 
       int bytes_downloaded = cursor.getInt(cursor 
         .getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); 
       int bytes_total = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); 

       if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL) { 
        downloading = false; 
       } 

       final int dl_progress = (int) ((double)bytes_downloaded/(double)bytes_total * 100f); 

       runOnUiThread(new Runnable() { 

        @Override 
        public void run() { 

         mProgressBar.setProgress((int) dl_progress); 

        } 
       }); 

       Log.d(Constants.MAIN_VIEW_ACTIVITY, statusMessage(cursor)); 
       cursor.close(); 
      } 

     } 
    }).start(); 

。任何幫助都會有所幫助。感謝 如果你想顯示從您的卡或存儲所有的視頻,你可以參考enter image description here

+0

發佈您當前的代碼 – Mushirih

回答

0

野兔 android scanning all .mp3 files in SD Card 和當前的視頻,你必須存儲當前的視頻在任何任何SQL或共享偏好文件,你可以從那裏得到的名字當完成從衛星或共享首選項中刪除

+0

但是如何從共享首選項獲取視頻後顯示進度條 –