2013-10-11 41 views
0

我在我的android應用中使用Dailymotion雲將視頻上傳到服務器。 我想上傳時顯示進度條,但我不知道如何獲取按字節值逐字節更新進度欄。如何顯示dailymotion雲端上傳的進度條

這是位DailyMotion雲API鏈接Dailymotion cloud api link

在互聯網上搜索,我發現這個progress bar in java,但我不知道我怎樣才能落實到位DailyMotion API的這種方法。

我使用異步任務顯示進度條 下面是Android的代碼上傳

 try 
     { 
      CloudKey cloud = new CloudKey(user_id, api_key); 
      File f = new File(selectedVideoPath); 
      String media_id = cloud.mediaCreate(f); 
      System.out.println(media_id); 
      Log.d("Testing", "media_id is"+media_id); 
     } 

這裏是位DailyMotion API的Cloud.class mediacreate()中,我想顯示進度條..任何想法

public String mediaCreate(File f) throws Exception 
{ 
    return this.mediaCreate(f, null, null); 
} 

public String mediaCreate(File f, DCArray assets_names, DCObject meta) throws Exception 
{ 
    String upload_url = this.fileUpload(); 

    PostMethod filePost = null; 
    int status; 
    try 
    { 
     filePost = new PostMethod(upload_url); 

     Part[] parts = { 
      new FilePart("file", f) 
     }; 

     filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); 

     HttpClient client = new HttpClient(); 
     client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); 
     status = client.executeMethod(filePost); 

     if (status == HttpStatus.SC_OK) 
     { 
      ObjectMapper mapper = new ObjectMapper(); 
      DCObject json_response = DCObject.create(mapper.readValue(filePost.getResponseBodyAsString(), Map.class)); 
      return this.mediaCreate(json_response.pull("url"), assets_names, meta); 
     } 
     else 
     { 
      throw new DCException("Upload failed."); 
     } 
    } 
    catch (Exception e) 
    { 
     throw new DCException("Upload failed: " + e.getMessage()); 
    } 
    finally 
    { 
     if (filePost != null) 
     { 
      filePost.releaseConnection(); 
     } 
    } 
} 

回答

1

我不能找到與你提到的位DailyMotion類這個產品的API支持。

如果您可以編輯該庫的來源,那麼你可以嘗試擴大MultipartRequestEntity並添加回調進步的支持,然後只需插上新課改在mediaCreate方法的位DailyMotion代碼:

filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); 

..用新的替換MultipartRequestEntity,例如。 ExtendedMultipartRequestEntity。

請參閱由Tuler和其他人在File Upload with Java (with progress bar)的答案,看看如何做到這一點。

一旦你通過回調得到更新,那麼你可以掛鉤進度條。