How Load Songs From Special Folder On Sd Card In My Listview And Play It?
I want to load songs from my custom folder which I made on sd card and play it in via my App. the path of this folder is on: /sdcard/Music/MyFolder Now I have a code which loads a
Solution 1:
use where condition in selection, like this.
finalCursormCursor= getContentResolver()
.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, newString[] { MediaStore.Audio.Media.DISPLAY_NAME, MediaStore.Audio.Media.DATA }, MediaStore.Audio.Media.DATA
+ " LIKE '/storage/sdcard0/Music/MyFolder/%'", null, "LOWER("
+ MediaStore.Audio.Media.TITLE + ") ASC");
Solution 2:
Use the following function to get list of files:
publicvoid listf(String directoryName, ArrayList<File> files) {
File directory = new File(directoryName);
// get all the files from a directory
File[] fList = directory.listFiles();
for (File file : fList) {
if (file.isFile()) {
files.add(file);
} elseif (file.isDirectory()) {
listf(file.getAbsolutePath(), files);
}
}
}
And on listview item click pass the path pf the file to mediaplayer.
Post a Comment for "How Load Songs From Special Folder On Sd Card In My Listview And Play It?"