Search code examples
androidandroid-mediaplayeraudio-player

Android: how the unknown album, artist, genre of music will be displayed?


I am developing a music application in Android, and when retrieving the album, artist, genre names of the songs, I get some unknown names.

For albums, the unknown album name is displayed as "music". For artists, the unknown artist name is displayed as "" and for Genres, the unknown genre is displayed as " "

Are these default names same on all the devices?? Because I want to rename those unknown names to more readable- Ex:"Unknown Artist" or "Unknown Album"

I had tried in only 2 devices and found that unknown album name is displayed as "music" BUT unknown artist name is displayed differently in both devices.

I would like to know how to handle these Unknown Names.


Solution

  • Seems You need UNKNOWN_STRING:

    The string that is used when a media attribute is not known. For example, if an audio file does not have any meta data, the artist and album columns will be set to this value.

    I've checked MediaPlayer android code here and, actually by default it's doing the following steps:

    • check if string from ContentProvider is UNKNOWN_STRING;
    • if so, it get changed with some string from the resource (by I'd doubt that You really need that strings);

    So, You need just to check data returned by ContentProvider for MediaStore.UNKNOWN_STRING and handle it whatever You like to. (e.g. provide the same string on all devices).
    For example, checkout com.android.music.MediaPlaybackActivity source, it has the following code:

    if (MediaStore.UNKNOWN_STRING.equals(albumName)) {
        albumName = getString(R.string.unknown_album_name);
        albumid = -1;
    }