Reputation: 2173
I have the following method which is meant to return the duration length (in ms) of a given raw resource.
private int getDurationLength(int id) {
MediaPlayer mp = MediaPlayer.create(context, R.raw.aboveingredients);
return mp.getDuration();
}
In my raw folder, I have a raw resource called aboveingredients.m4a
as shown in the image below.
When the following code is executed:
audioDuration.setText(getDurationLength(R.raw.aboveingredients));
I receive the following error in Logcat:
android.content.res.Resources$NotFoundException: String resource ID
Any help is appreciated.
Upvotes: 1
Views: 1161
Reputation: 45490
setText
expect you to pass in a String not an integer
get the string
value to avoid the error
int soundLength = getDurationLength(R.raw.aboveingredients);
audioDuration.setText(String.valueOf(soundLength));
or add concatenation to a string
audioDuration.setText("soundLength = " + soundLength);
Upvotes: 1