0

I have been working on a MediaPlayer app, where I use the MediaStore.Audio.Media to get all the songs on the SD card and their title, album, artist, etc. tags. I have a custom adapter where I want to check if the Artist field is empty, so I could set "Artist unknown" for that field. The adapter and the cursor I use are in my opinion irrelevant to this question so I'm not going to paste any code here, since this problem occurs outside the adapter as well.

Here is the problem: when an mp3 song doesn't have an artist tag, the cursor for the artist field (the MediaStore.Audio.Media.ARTIST field) returns "". I have no idea what kind of data type that is (it should be String) because whenever I compare it to a String with the value "", the comparison is false. Even if I assign the return value of that field to a temporary String, and than compare that with the before mentioned "", I still get false. I even tried null, "unknown", "", nothing works. I've really hit a dead end here and any kind of help would be greatly appreciated.

Thank you in advance, Ivan.

1 Answer 1

1

I'm using the very same field (MediaStore.Audio.Media.ARTIST), but what I noticed is different. When you try to retrieve the song's artist info and currently ther's no info available, what you get is <unknown> string.

I wanted to change that info too and I just went for a:

String artist = (((cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)) == null) 
                            || cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)).equals("")
                            || cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)).equals("<unknown>")) ? 
                "Artist Unknown" : cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)));

the "null and equals.("")" checks should be useless anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.