Skip to content Skip to sidebar Skip to footer

How To Get Songs From Album/artist In Android,using Mediametadataretriever?

First of all i am a newbie and secondly i know there exists a solution for 'How to get songs from album in android?' but that is by using cursor and MediaStore and i have used Med

Solution 1:

Check out this tutorial:

http://www.srikanthtechnologies.com/blog/android/audioplayer.aspx

You can modify it slightly to suit your needs:

private ArrayList<SongDeatils> getSongList(File musicFolder) {
    ArrayList<SongDeatils> songs = newArrayList<SongDeatils>();

    for (File f : musicFolder.listFiles()) {
        MediaMetadataRetrievermd=newMediaMetadataRetriever();
        md.setDataSource(musicFolder + "/" + f.getName());

        // Assign variables like title, artist, etcSongDeatilss=newSongDeatils();
        s.setTitle(title);
        s.setArtist(artist);
        s.setSong(f.getPath());
        // ...

        songs.add(s);
    }     

    return songs;
}

For image (cover art) handling, it should really be done asynchronously in the adapter. I'd suggest using Universal Image Loader.

Update:

Just saw your comments. What you really want is an efficient way to list songs from a specific album or artist, without using file filters and sorting. The only other option, then, is to use MediaStore/Cursor. There are different types of queries that you can construct, depending on how you are trying to view the data.

So, to query for a list of artist, you would use MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI and use the artist name as your selection args.

For a list of albums, you now have the ARTIST_KEY which you can use to query MediaStore.Audio.Artists.Albums.EXTERNAL_CONTENT_URI, to obtain a list of albums for the given artist.

For an example of how to list all albums for a given artist, see here.

Solution 2:

@Anknit Mediastore do not detect the all directories in your device. I no it scans very much faster than what we try to build our own code. But it do no detect some folder. Today I am creating my project in my phone I have directories namely .trash-100 & .trash it contains almost .mp3 files. It were not detected by even the VLC and by default music player except the Poweramp. Please refer the following link http://mrbool.com/how-to-extract-meta-data-from-media-file-in-android/28130 I just used recursion for that and it worked fine

Post a Comment for "How To Get Songs From Album/artist In Android,using Mediametadataretriever?"