Trying to get song metadata with Spotify Android SDK results in illegal argument exception

287 views Asked by At

I'm trying to get song metadata with the Spotify Android SDK without buffering the song. Here's my code:

public String getTitleFromURI(String uri) {

    //uri = "spotify:track:6ORqU0bHbVCRjXm9AjyHyZ"

    MediaMetadataRetriever retriever = new MediaMetadataRetriever();

    Uri temp = Uri.parse(uri);

    System.out.println("URI: " + temp + "\n");

    retriever.setDataSource(uri); // java.lang.IllegalArgumentException

    return retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);

}

I'm unsure as to why I'm receiving an illegal argument exception.

1

There are 1 answers

0
Aaron On

Ended up using this: https://github.com/kaaes/spotify-web-api-android

public String getTitleFromURI(String uri) {
    return spotifyService.getTrack(uri.split(":")[2]).name;
}

Thanks for your help!