I've got this Javascript code for my phonegap application for downloading a soundfile into the Ringtones folder. Since it can take while downloading it and until the alert pops up, I'd like to insert a .gif while the file is downloading.. How can i do this? This is my code:
var fileTransfer = new FileTransfer();
fileTransfer.download(
"http://example.com/Sound.mp3",
"file://sdcard/Ringtones/Sound.mp3",
function(entry) {
alert("Sound downloaded!" );
},
function(error) {
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
});
}
Have this where you want on your page:
<div id="loadingImg" style="display:none;">
<img src="load.gif" />
</div>
then display/hide it at relevant points in your code (perhaps using jQuery ):
var fileTransfer = new FileTransfer();
//Fade in the loadingImg Div at the start of your function
$("loadingImg").fadeIn();
fileTransfer.download(
"http://example.com/Sound.mp3",
"file://sdcard/Ringtones/Sound.mp3",
function(entry) {
//Fade out the loadingImg Div on success
$("loadingImg").fadeOut();
alert("Sound downloaded!");
},
function(error) {
//Fade out the loadingImg Div on error
$("loadingImg").fadeOut();
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
});
}
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.