I’d like to:
- Generate a random number (easy enough)
- take that random number and add it to some sort of dynamic path
- use the dynamic path in the mediaplayer creation.
E.g.
Resource folder(raw) contains
1.mp3
2.mp3
3.mp3
Random number generates a number between 0 and 4
e.g: 2
Inserts random number to path
E.g. a String?
String PATH = "R.raw." + RANDOM-NUMBER
MediaPlayer mp = MediaPlayer.create(context, PATH);
However, of course MediaPlayer uses a URI variable not a string, i did try
myUri = Uri.parse("R.raw.2");
but get a nullPointerException
I imagine this is very simple/straight forward to answer and my knowledge simply evades me
Thanks very much
You cant do that with resources. Here’s how I see you’d go about it.
AFAIK, you have to use setDataFromResource to set the data for your media player from R.raw