How to filter out only relevant Media files in Android?
android, android-mediaplayer
Solution
You can filter using MediaStore.Audio.AudioColumns class.That will return lots of value of Audio file and you can use it.
musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
proj, MediaStore.Audio.Media.DURATION + ">= 60000", null, null);
- Filter by Duration - The duration of the audio file, in ms
- Filter by Type-Music -Non-zero if the audio file is music
- Filter by Type-RingTone - Non-zero if the audio file may be a ringtone
- Filter by Type-Alarm - Non-zero if the audio file may be an alarm
Check for more reference
Problem
I'm trying to fetch all the music files in my phone: For this I'm using: ``` String[] STAR = {"*"}; Uri allExternalSongUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0"; Cursor cursor = getContentResolver().query(allExternalSongUri, STAR, selection, null, null); if(cursor != null){ if(cursor.moveToFirst()){ do { String songName = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)); Log.i("name", songName); } while (cursor.moveToNext()); } cursor.close(); } ``` But above code, apart from getting music files, is also fetching some additional unnecessary files like *sound_screen_on.mp3* (which is installed & used by some other app). Issue is my native android music player does not list & plays these unnecessary files. How can I filter files like these.