Reputation: 206
I am developing a simple calculator for a device, there I am using mediaplayer to play some sound when a button is pressed using
media=MediaPlayer.create(this, R.raw.wipe);
media.start();
and in a reset button i am releasing it with
media.release();
but after some button clicks it stops playing any sound. How can I fix this problem?
Upvotes: 0
Views: 382
Reputation: 267
On click of reset button , also use media.reset(); after media.release();
Upvotes: 0
Reputation: 14038
MediaPlayer is not a good option when you are playing small sound effects as the user can click on multiple buttons very soon and you will have to create a MP object for all of them which doesnt happen synchronously. That is why you are not hearing sounds for every click. Go for the SoundPool Class which allows you to keep smaller sounds loaded in memory and you can play them any time you want without any lag which you would feel in a mediaplayer. http://developer.android.com/reference/android/media/SoundPool.html Here is a nice tutorial : http://www.anddev.org/using_soundpool_instead_of_mediaplayer-t3115.html
Upvotes: 1
Reputation: 4670
try like this,
MediaPlayer media=MediaPlayer.create(this, R.raw.wipe);
media.start();
On reset button write like:
media.release();
media.reset();
Upvotes: 0