Skip to content

Commit

Permalink
API
Browse files Browse the repository at this point in the history
  • Loading branch information
xjxxjx1017 committed Dec 20, 2015
1 parent f8e5ec3 commit 0bbbbd2
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions exernalStorageSdcardAccess.js
@@ -0,0 +1,72 @@


var ExternalStorageSdcardAccess = function ( _fileHandler, _errorHandler ) {

var errorHandler = _errorHandler || _defultErrorHandler;
var fileHandler = _fileHandler || _defultFileHandler;
var root = "file:///";

return {
scanRoot:scanRoot,
scanPathList:scanPathList,
scanPath:scanPath
};

function scanPath( path ) {
window.resolveLocalFileSystemURL(path, _gotFiles, errorHandler );
}

function scanRoot() {
scanPath( root );
}

function scanPathList( arrayOfPath ) {
arrayOfPath.forEach( function ( p ) {
scanPath( p );
} );
}

function _gotFiles(entry) {
// ? Check whether the entry is a file or a directory
if (entry.isFile) {
// * Handle file
fileHandler( entry );
}
else {
// * Scan directory and add media
var dirReader = entry.createReader();
dirReader.readEntries( function(entryList) {
entryList.forEach( function ( entr ) {
_gotFiles( entr );
} );
}, errorHandler );
}
}

function _defultFileHandler(fileEntry){
console.log( "FileEntry: " + fileEntry.name + " | " + fileEntry.fullPath );
}
function _defultErrorHandler(error){
console.log( 'File System Error: ' + error.code );
}
};


/*
var SAMPLE_PATH_LIST= [
"cdvfile://localhost/", // * Err 5
"file:///", // * root
"file:///storage/", // * storage
"file:///storage/sdcard1/music", // * Err 1
"file:///storage/sdcard1/music/", // * acg
"file:///storage/sdcard1/music/ACG/aaaaa.mp3", // * OK
];
// Test:
new ExternalStorageSdcardAccess( fileHandler, null ).scanPath( "file:///storage/sdcard1/music" );
function fileHandler( fileEntry ) {
console.log( fileEntry.name + " | " + fileEntry.toURL() );
}
*/

0 comments on commit 0bbbbd2

Please sign in to comment.