Last active
December 29, 2015 09:49
-
-
Save et4891/7653187 to your computer and use it in GitHub Desktop.
FIle API - Phonegap (File List In Directory)
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", 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