You can do it like this:
int resId = context.getResources().getIdentifier("tch_swan_lake", "raw", context.getPackageName());
melody = MediaPlayer.create(this, resId);
Question
For example, I have a string "R.raw.tch_swan_lake"
. I want to play one of many files in the raw folder, which match to my string:
melody = MediaPlayer.create(this, R.raw.tch_swan_lake);
How to use a string as a resource pointer?
La solution
You can do it like this:
int resId = context.getResources().getIdentifier("tch_swan_lake", "raw", context.getPackageName());
melody = MediaPlayer.create(this, resId);
Autres conseils
This is how i get play able resource from 'raw;
Uri uri =Uri.parse("android.resource://" + getPackageName() + "/raw/" + imageName);// without extention