Issue
I have raw folder and inside that I have added 3 mp3
files. And am retrieving the file name like this:
Field[] fields=R.raw.class.getFields();
for(int count=0; count < fields.length; count++){
Log.e("RawName: ", fields[count].getName());
}
String resid=fields[0].getName();
I just need only 0th position file. Now I have set the value like this,
AssetFileDescriptor afd = getResources().openRawResourceFd(R.raw.test);
// Build and start first player
MediaPlayer player1 = MediaPlayer.create(this, R.raw.test);
player1.start();
MediaPlayer player2 = MediaPlayer.create(this, R.raw.test);
My question is how can I set the value resid in to that "R.raw.test".
Solution
Field[] fields=R.raw.class.getFields();
for(int count=0; count < fields.length; count++){
Log.e("RawName: ", fields[count].getName());
}
String resid=fields[0].getName();
try {
Class res = R.raw.class;
Field field = res.getField(resid);
rawId = field.getInt(null);
}
catch (Exception e) {
Log.e("MyTag", "Failure to get drawable id.", e);
}
/*music repeat*/
afd = getResources().openRawResourceFd(rawId);
// Build and start first player
player1 = MediaPlayer.create(this, rawId);
player1.start();
player2 = MediaPlayer.create(this, rawId);
player1.setNextMediaPlayer(player2);
Answered By - Sunisha Sindhu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.