Skip to content

Instantly share code, notes, and snippets.

@et4891
Last active December 29, 2015 09:49
Show Gist options
  • Save et4891/7653187 to your computer and use it in GitHub Desktop.
Save et4891/7653187 to your computer and use it in GitHub Desktop.
FIle API - Phonegap (File List In Directory)
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
}
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getDirectory("Music", {create: false, exclusive: false}, getDirSuccess, fail);
}
function getDirSuccess(dirEntry) {
// Get a directory reader
var directoryReader = dirEntry.createReader();
// Get a list of all the entries in the directory
directoryReader.readEntries(readerSuccess,fail);
}
function readerSuccess(entries) {
var i;
for (i=0; i<entries.length; i++) {
// Assuming everything in the Music directory is an mp3, go nuts
// otherwise check entries[i].name to see if it ends with .mp3
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment