android - Getting the Title of an MP3 throws "java.lang.IllegalArgumentException" -


why code throw illegalargumentexception? want show title of mp3-file located @ "raw" folder

mediaplayer = mediaplayer.create(getactivity(), r.raw.willy_william_ego);             mediametadataretriever mmr = new mediametadataretriever();             uri uri = (uri) uri.fromfile(new file("android.resource://com.hthl.kellergassen_app/raw/willy_william_ego"));             mmr.setdatasource(getactivity(), uri);             string title = mmr.extractmetadata(mediametadataretriever.metadata_key_title); 

assuming you're getting issue in setdatasource, it'll because uri you're passing in isn't valid reason - because file couldn't found. sure it's present name , doesn't have file extension?

from javadoc...

void setdatasource (context context, uri uri)

sets data source content uri. call method before rest of methods in class. method may time-consuming.

parameters context context: context use when resolving uri uri uri: content uri of data want play

throws illegalargumentexception if uri invalid securityexception if uri cannot used due lack of permission.

update - having looked @ code, seems you're using hard-coded string com.hthl.kellergassen_app package name, that's not right. according stacktrace it's com.htlhl.kellergassen_app - note "l" in "htlhl" (this in string use create uri).


Comments