Returns artist associated with song - Android Media

Android examples for Media:Song

Description

Returns artist associated with song

Demo Code


//package com.java2s;

import android.media.MediaMetadataRetriever;

public class Main {
    /**/*  w  w  w. j  a  va 2s  .c o m*/
     * Returns artist associated with song
     *
     * @param filePath Path to song
     * @return artist of song, null on fail
     */
    public static String getArtist(String filePath) {
        try {
            MediaMetadataRetriever metaRetriver = new MediaMetadataRetriever();
            metaRetriver.setDataSource(filePath);
            return metaRetriver
                    .extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
        } catch (Exception e) {
            return "N/A";
        }
    }
}

Related Tutorials