Issue
I have an array of strings (for sound file names) , and i have the exact files attached to the projects as resources (raw), i am trying to fetch the ID of these resources via code in order to change which file (resource) to be playing from within the code.
String[] phrasesDesc = {"doyouspeakenglish.m4a",
"goodevening.m4a",
"hello.m4a",
"howareyou.m4a",
"ilivein.m4a",
"mynameis.m4a",
"please.m4a",
"welcome.m4a"
};
int index = 0;
for (String str : phrasesDesc) {
String res_name =phrasesDesc[index] ;
resourceID[index] = this.getResources().getIdentifier(res_name, "raw", this.getPackageName());
System.out.println(res_name +" "+ resourceID[index]);
index++;
}
please help.
Solution
You need to query them without the file-type extension:
String[] phrasesDesc = {"doyouspeakenglish", "goodevening", "hello", "howareyou", "ilivein", "mynameis", "please", "welcome"};
or somehow strip the file-type extension, eg: res_name.replace(".m4a", "")
.
Answered By - Martin Zeitler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.