-
-
Save fhferreira/8539444 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('deviceready', deviceready, false); | |
var buttomDom; | |
var statusDom; | |
var fileSystem; | |
function deviceready() { | |
console.log('dv ready'); | |
//step one is to request a file system | |
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, | |
function(fs) { | |
fileSystem = fs; | |
buttonDom = document.querySelector('#startDl'); | |
buttonDom.addEventListener('touchend', startDl, false); | |
buttonDom.removeAttribute("disabled"); | |
statusDom = document.querySelector('#status'); | |
}, function(e) { | |
alert('failed to get fs'); | |
alert(JSON.stringify(e)); | |
}); | |
} | |
function startDl() { | |
buttonDom.setAttribute("disabled","disabled"); | |
var ft = new FileTransfer(); | |
var uri = encodeURI("http://archive.org/download/Kansas_Joe_Memphis_Minnie-When_Levee_Breaks/Kansas_Joe_and_Memphis_Minnie-When_the_Levee_Breaks.mp3"); | |
var downloadPath = fileSystem.root.fullPath + "/download.mp3"; | |
ft.onprogress = function(progressEvent) { | |
if (progressEvent.lengthComputable) { | |
var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100); | |
statusDom.innerHTML = perc + "% loaded..."; | |
} else { | |
if(statusDom.innerHTML == "") { | |
statusDom.innerHTML = "Loading"; | |
} else { | |
statusDom.innerHTML += "."; | |
} | |
} | |
}; | |
ft.download(uri, downloadPath, | |
function(entry) { | |
statusDom.innerHTML = ""; | |
var media = new Media(entry.fullPath, null, function(e) { alert(JSON.stringify(e));}); | |
media.play(); | |
}, | |
function(error) { | |
alert('Crap something went wrong...'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment