【发布时间】:2013-10-15 01:09:16
【问题描述】:
我在我的 Android 应用程序中使用 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();
}
}
}
【问题讨论】:
标签: java android httpclient android-progressbar