sorry for my bad english.. probably you’ll see some grammar errors..
I’m learning to program an android application and I need help.
I would like to put some mp3 files in ‘res/raw‘ folder and i would like to put specific text on each item on the Listview. So when the user clicks on the item he wants (for example a song title), the associated mp3 starts.
I would like if you can teach me how to play just one mp3 at time (beacause the user could clicks many items during the first mp3 playing).
I’m new in the android world so please be patient and use simple terms 🙂
Have a nice day,
Riccardo.
As your question does not include any specific code of yours I can give you a few guidelines.
Declare a class member reference to the MediaPlayer instance. e.g. it should be declared in the class’s scope, and not in any method within it:
In your OnClickListener, check if the instance is null, and if not, stop and release it, and create a new instance with the new song.
If instead of create you decide to use
prepareAsync(), make sure that you don’t call start right after preparation, but instead assign aOnPreparedListenerand call start in it.Except of that, follow the guidelines in the MediaPlayer reference.