Reputation: 889
To get all local Music-Files on an android-Device I'm working with a ContentResolver, getting Data from MediaStore.Audio. Here's an example on how I load all titles + their artist:
ContentResolver musicResolver = act.getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + "!= 0";
String sortOrder = MediaStore.Audio.Media.TITLE + " ASC";
Cursor musicCursor = musicResolver.query(musicUri, null, selection, null, sortOrder);
if(musicCursor!=null && musicCursor.moveToFirst()){
int titleColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
int artistColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.ARTIST);
do {
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
//save them somewhere
}while (musicCursor.moveToNext());
}
So this code is working for about 75% of all the music I have.
But there are tracks, where artist (and some other values like artistKey, Track, Cover,...) return null. But the title, album_name and artistId are loading correctly.
The Tags should be right (shown right on the Computer and other Music-Apps). Also the format isn't different to the tracks that are working.
Have anyone of you had the same problem some day and solved this?
All those missing Meta-Tags are not even loading with a MediaMetadataRetriever
. I can't explain what's the problem with some of my Files and why other apps can load them correctly.
If needed, I can upload a working and a not-working Music-File somewhere.
Upvotes: 2
Views: 209
Reputation: 889
Managed how to do it.
Some albums have only stored the most information (aristname, albumcover) in one (mostly the first or last) of the tracks, not all. This is not very common, but about 20% of my albums had this, even they were bought.
So, if you are loading/displaying one of these albums, you need to go through all album-tracks until you find the one, where the information you are missing on the others is stored. I made it a bit different because of my other code, but I think this is the most understandable way to do it.
Upvotes: 1