Display progress bar using jquery in phonegap android for multiple files upload / download

巧了我就是萌 提交于 2019-12-20 04:06:55

问题


I am creating an app in which i want to show the progress bar for multiple file downloads and upload from the server. I tried the example of Raymondcamden for displaying the progress of the file. I tried to use the same for multiple files but its progress bar varies while downloading the file here is the code that i tried for multiple files:

function startDl() {
console.log('in startD1 function');

var progressbar = $("#progressbar"),progress_Label = $(".progress-label");
    progressLabel = document.getElementById('progress-label');

progressLabel.style.visibility = "";
progressLabel.style.display = "block";

var download_url = ["http://archive.org/download/Kansas_Joe_Memphis_Minnie-When_Levee_Breaks/Kansas_Joe_and_Memphis_Minnie-When_the_Levee_Breaks.mp3",
                    "http://archive.org/download/Kansas_Joe_Memphis_Minnie-When_Levee_Breaks/Kansas_Joe_and_Memphis_Minnie-When_the_Levee_Breaks.mp3",
                    "http://archive.org/download/Kansas_Joe_Memphis_Minnie-When_Levee_Breaks/Kansas_Joe_and_Memphis_Minnie-When_the_Levee_Breaks.mp3" ]
var ft = new FileTransfer();
for(var i=0;i<download_url.length;i++)
{   
    var uri = encodeURI(download_url[i]);

    var downloadPath = fileSystem.root.fullPath + "/download.mp3";  
    ft.download(uri, downloadPath, function(entry) {
        progressbar.progressbar({
            disabled: true
        });
        var media = new Media(entry.fullPath, null, function(e) {
            console.log('error in download')
            alert(JSON.stringify(e));
        });
        media.play();
    }, function(error) {
        alert('Crap something went wrong...');
    });
}
ft.onprogress = function(progressEvent) {
    if (progressEvent.lengthComputable) 
    {
        var perc =    Math.round( (progressEvent.loaded / progressEvent.total) * 100 );

        progressbar.progressbar({
            value : perc,
            change : function() {
                progress_Label.text(progressbar.progressbar("value") + "%");
            },
            complete : function() {
                progress_Label.text("complete!");
            }
        });
    }
};
}

Any help is appreciated. Thanks in advance

来源:https://stackoverflow.com/questions/20510524/display-progress-bar-using-jquery-in-phonegap-android-for-multiple-files-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!