I am trying to access audio files in my phone from my application. I am relatively new to Android Programming. Can someone help me with this?
Asked
Active
Viewed 64 times
-1
-
Have you searched for this? Plenty of questions regarding accessing files on the internal storage. Show us some effort first – Denny May 03 '17 at 11:47
-
You should search before asking, here is one [example](http://stackoverflow.com/questions/22323438/how-to-find-mp3-files-from-sdcard-in-android-programatically). – Chetan May 03 '17 at 11:50
-
Query the `MediaStore` for media with the MP3 MIME type. – CommonsWare May 03 '17 at 12:10
1 Answers
0
Please try this
String path="/sdcard/"; /* assuming u wanted to start from your sdcard */
private void updatePlaylist(){
File home=new File(path);
if (home.listFiles(new MP3filter()).length>0){
for (File file: home.listFiles(new MP3filter())){
alist.add(file.getName());
}
}
if (alist.size()==0){
tv.setText("No music files");
}
else
tv.setText(alist.get(0).toString());
}
class MP3filter implements FilenameFilter {
@Override
public boolean accept(File dir, String filename) {
return (filename.endsWith(".mp3"));
}
}

djdere
- 321
- 2
- 10
-
-
-
Dont you think OP wants all mp3 files? So also those from /sdcard/Music and /sdcard/mp3s ? And so on? Of all subdirectories? You know the concept of recursive? Unclear if you do. – greenapps May 04 '17 at 06:12
-
i know the concept of recursive and i've got your point. i just posted this for starters. i actually appreciate it if you can suggest an edit @greenapps – djdere May 04 '17 at 06:27