Aaron
Aaron

Reputation: 21

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

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.

Upvotes: 0

Views: 292

Answers (1)

Aaron
Aaron

Reputation: 21

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!

Upvotes: 2

Related Questions