Reputation: 3
Why does this code throw a IllegalArgumentException? I want to show the Title of an MP3-File which is located at the "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);
Upvotes: 0
Views: 474
Reputation: 3146
Assuming you're getting the issue in setDataSource, it'll be because the URI you're passing in isn't valid for some reason - most likely because the file couldn't be found. Are you sure it's present with that name and doesn't have a file extension?
From the Javadoc...
void setDataSource (Context context, Uri uri)
Sets the data source as a content Uri. Call this method before the rest of the methods in this class. This method may be time-consuming.
Parameters context Context: the Context to use when resolving the Uri uri Uri: the Content URI of the data you want to play
Throws IllegalArgumentException if the Uri is invalid SecurityException if the Uri cannot be used due to lack of permission.
UPDATE - Having looked at your code, it seems you're using the hard-coded String com.hthl.kellergassen_app
as the package name, but that's not right. According to the stacktrace it's com.htlhl.kellergassen_app
- note the extra "l" in "htlhl" (this is in the String you use to create the URI).
Upvotes: 1