I'm trying to do something with Uri that feels like it should be relatively simple but I haven't found a straight answer anywhere, maybe what I'm trying to do doesn't require the use of Uri.
In my project's res/raw folder I have a bunch of .wav files that have identical names but end in different numbers:
res/
raw/
sample_0.wav
sample_1.wav
sample_2.wav
sample_3.wav
I want to load one of them in a SoundPool
with something like this:
Soundpool sp = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
public void playSound(int i, Activity a){
spPath = Uri.parse("android.resource://jgjp.com.appname/raw/R.raw.sample_"+i);
int spID = sp.load(a, spPath, 1);
sp.play(spID, 1, 1, 1, 0, 1);
}
I'm using the Uri object because I want to be able to change the last digit of the resource's file name based on the received argument.
My problem is with the line int spID = sp.load(a, spPath, 1);
where it's expecting spPath to be an int rather than a Uri. I know that resource identifiers like R.raw.sample_1
actually return int values, how do I get the corresponding int from the Uri class after I've set it with Uri.parse()?
Checking through the android documentation for the Uri class hasn't yielded much and while I can find plenty of tutorials about setting the Uri I can't find much about how to use it.