java - Playing musics with ImageButton android -


i have list of music (.mp3) want played imagebutton , want play each sound id

first, have database has field _id. then, tried

 final string ambil = kata.get(3) 

for retrieving _id query used. then, used

speaker.settag(ambil); 

speaker imagebutton want tag each button _id make sound different each other.

then, ordered of sound file have this

int names[] = {r.raw.a,r.raw.a,r.raw.c}; 

finally, want create mediaplayer this

mediaplayer mp = mediaplayer.create(lazyadapter.this, r.raw.names[ambil]); 

is algorithm right ?

for now, give hint how done in simple way. can create array raw resources:

 int names[] = new int {r.raw.a,r.raw.b,r.raw.c}; 

don´t make string array have done it, not work. use example above , create mediaplayer this:

 mediaplayer mp = mediaplayer.create(lazyadapter.this, names[0]); 

edit

from example above, see wrong things.

first, can´t pass string identify number of array. did this:

     final string ambil = kata.get(3) 

and trying resource mediaplayer like:

     mediaplayer mp = mediaplayer.create(lazyadapter.this, r.raw.names[ambil]); 

there pass string resource names[] ---> r.raw.names[ambil]]; don´t write r.raw.names[], write names[].

also, have pass integer value array like:

      names[0] 

the question is, integer database, id, value? explanation, if write names[0], means first value of array (because arrays starts 0). in case, refer resource r.raw.a . if want refer second song, have write names[1].

i don´t know how have database implemented , in way give _id. sure give _id in way, not higher number of resources. if create autoincrement id, not work in case, when value higher number of songs.


Comments

Popular posts from this blog

double exclamation marks in haskell -

qml - Is it possible to implement SystemTrayIcon functionality in Qt Quick application -

Qt Creator - Searching files with Locator including folder -