简体   繁体   中英

how can i display progress bar for dailymotion cloud uploading

I am using Dailymotion cloud in my android app to upload videos to server. i want to display progress bar while uploading but i don't know how can i get byte by byte value to update progress bar.

This is dailymotion cloud api link Dailymotion cloud api link

While searching on internet i found this progress bar in java but i don't know how can i implement into this method of dailymotion api.

I am using async task to display progress bar Here is android code for uploading

      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);
        }

And here is Dailymotion API's Cloud.class mediacreate() in which i want to display progress bar .. any idea

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();
        }
    }
}

I'm not able to find any api support for doing this with the DailyMotion class that you mentioned.

If you can edit the source of that library, then you could try extending MultipartRequestEntity and add support for callbacks for progress, and then just plug in that new class in the DailyMotion code in the mediaCreate method:

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

.. replace MultipartRequestEntity by the new one, eg. ExtendedMultipartRequestEntity.

See the answer by Tuler and others at File Upload with Java (with progress bar) to see how to do it.

Once you are getting updates via the callback, then you can hook up progress bar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM