I have an array of sound
int mySounds ={R.raw.sound1,R.raw.sound2,R.raw.sound3}
Am later creating a sound by
mp开发者_如何转开发 = MediaPlayer.create(this,mySounds[0] );
mp.start();
Was wondering if there is anyway to just use strings in the array
String mySounds ={"sound1.mp3","sound2.mp3"}
Yes, it's possible. You have to look up the resource by using getIdentifier
String mySounds ={"sound1","sound2"};
int mp3Resource = getResources().getIdentifier(mySounds[0], "raw" , String packageName);
mp = MediaPlayer.create(this,mp3Resource );
mp.start();
Resource names are without extension. So it's not sound1.mp3, but sound1.
精彩评论