last day (15 days later) » 

6:40 AM
1
A: List All Mp3 files in android

Madhanhere I've modified your getPlayList() method. look into it. ArrayList<HashMap<String,String>> getPlayList(String rootPath) { ArrayList<HashMap<String,String>> fileList = new ArrayList<>(); try { File rootFolder = new File(rootPath); File[...

 
thank you so much man. its works for me. and you have saved my so many hours... thank you once again.
 
glad to help. It will be appreciated if you mark this as an answer.
 
Hi @Madhan Again i am troubling you. Can we restrict recursive till 3 or 5 folders. Its looping to all sub folders and its taking so much time. i tried to stop after 3 folers search buts its not working. Thank you.
 
If it takes too much of time to fetch all your data means then run this method in the separate thread. don't restrict it without having any valid reason. you can use AsyncTask class to solve this issue
 
yes we can make it on seprrate thread but i want to restrict scan till 5 sub folders. becouse we never know how many sub folders are there on users devices. so i want to make recursive function loop till 5 folders. after that it should return to next folder.
 
6:40 AM
yes, you can. make an int variable outside the getPlayList() method. and increment this int variable once it enters the if (file.isDirectory()) { block, before that you should check. is the int variable is less than 5 to proceed the if (file.isDirectory()) { block
hi
did you try the steps that i said?
 
ok, but by this logic it will run only for 5 folders. whter its sub or root. we need to re intializ int variable
try {
File rootFolder = new File(rootPath);
File[] files = rootFolder.listFiles(); //here you will get NPE if directory doesn't contains any file,handle it like this.
for (File file : files) {
if (folderno < 3 && file.isDirectory()) {
folderno = folderno + 1;

if (getPlayList(file.getAbsolutePath()) != null) {

fileList.addAll(getPlayList(file.getAbsolutePath()));
} else {

break;
}
} else if (file.getName().endsWith(".mp3")) {

folderno=folderno-1;
HashMap<String, String> song = new HashMap<>();
 
yes at end you should reset the variable. for next use
 
ok let me try that
hey need to test this. seems this logic will work. thank you again. ur life saver.....
but seems this logic has some loop... its going inside.. mean if sub folder has many folders its acting as new list and looping it.
/storage/sdcard0/mipush/log/com.android.fileexplorer/com.android.fileexplorer/co‌​m.android.fileexplorer/com.android.fileexplorer/com.android.fileexplorer/com.andr‌​oid.fileexplorer/com.android.fileexplorer/com.android.fileexplorer/com.android.fi‌​leexplorer/com.android.fileexplorer/com.android.fileexplorer/com.android.fileexpl‌​orer/com.android.fileexplorer/com.android.fileexplorer
like it loop this
 
7:00 AM
can you post your updated code. so it will be easy to identify the problem.
 
public class SongsManager {
// SDCard Path
//final String MEDIA_PATH = new String("/sdcard/");
final String MEDIA_PATH = Environment.getExternalStorageDirectory() + "";

private ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();

// Constructor
public SongsManager() {

}

/**
* Function to read all mp3 files from sdcard
* and store the details in ArrayList
*/
int folderno = 0;

public ArrayList<HashMap<String, String>> getPlayList(String rootPath) {
ArrayList<HashMap<String, String>> fileList = new ArrayList<>();
 
you don't want to decrement the folderno in else if condition because it's a file that belongs to same path as the dir not the next one.
 
ok let me chk
now need to leave for office... will be back in evn. thank you again for your help. and very sorry that i trouble you again and again.
 
7:25 AM
that's fine. okay, let me know once you achieve this.
 

  last day (15 days later) »