我正在创建一个应用程序,我想在其中显示多个文件下载的进度条并从服务器上传。我尝试了Raymondcamden的示例来显示文件的进度。我尝试对多个文件使用相同的但是它的进度条有所不同,这里下载文件是我为多个文件尝试的代码:
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!");
}
});
}
};
}
感谢任何帮助。 提前致谢