Reputation: 8946
I need to list every Audio and video files together in a listview.
I know how to list Audio and how to list video separately using
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
MediaStore.Video.Media.EXTERNAL_CONTENT_URI
Is there any other way i can list both audio and video together.
Upvotes: 0
Views: 511
Reputation: 34311
you can use the below code,
File home = Environment.getExternalStorageDirectory();
if (home.listFiles( new MusicFilter()).length > 0) {
for (File file : home.listFiles( new MusicFilter())) {
songs.add(file.getAbsolutePath());
}
ArrayAdapter<String> songList = new ArrayAdapter<String>
(this,R.layout.song_item,songs);
setListAdapter(songList);
}
class MusicFilter implements FilenameFilter
{
public boolean accept(File dir, String name)
{
if (name.endsWith(".mp3")||name.endsWith(".3gp")||name.endsWith(".mp4"))
return true;
else
return false;
}
}
Here songs is a ArrayList which stores the actual path of the song.
Upvotes: 1