Song Array

All your problems with Audio, Video and Images.

Song Array

Postby marcjc » Tue Feb 09, 2010 7:04 pm

new app I am working on....

I would like to create a single button that starts the music (mp3 in the raw folder) (getting the a song to play when a button is pressed is the easy part).... then press the same button to skip to the next song.

To me this sounds like I need an array of songs declared somewhere, then when the button is pressed it parses and goes to the next song.

Just not sure how to do this, or if this is even correct thinking.

Any help would be appreciated.
marcjc
Junior Developer
Junior Developer
 
Posts: 16
Joined: Tue Jan 05, 2010 3:16 pm

Top

Postby mitutitu » Tue Feb 09, 2010 8:07 pm

Hello marcjc, You can keep an array of song resource ids. Then traverse each index of resource ids array as you press button by setting a incremental/decremental variable for array index. The array could be much more like this:

Code: Select all
int[] songs = {R.raw.song1,R.raw.song2,R.raw.song3,....etc};


Hope you got the idea and can make it better for you.

Have fun :)

Thanks,
mitu
User avatar
mitutitu
Senior Developer
Senior Developer
 
Posts: 113
Joined: Tue Jun 09, 2009 7:40 am
Location: St. John's, NL, Canada

Postby marcjc » Tue Feb 09, 2010 8:47 pm

Got this declared but not sure how to call it in my code:

Code: Select all
final int[] songs = {R.raw.ef101a, R.raw.ef101b, R.raw.ef101c, R.raw.ef101d, R.raw.ef101e};


Code: Select all
public void onClick(View arg0) {
                 MediaPlayer mp = MediaPlayer.create(efaustusa.this, songs);
                 mp.start();


Thank you for your help.

-Marc
marcjc
Junior Developer
Junior Developer
 
Posts: 16
Joined: Tue Jan 05, 2010 3:16 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 18 guests