Dont call release when it is still playing. The start() function
returns immediatly. So it could still run.
Release it, when it is finished. If this doesnt work out, create them
once as class members (and release at onDestroy).
Dont forget that a long sound will disturb the ui thread. In this case
you have to create a thread for sound playing.
Did you also saw the class SoundPool ?
Try something like this:
final MediaPlayer mp = MediaPlayer.create(getBaseContext(),
R.raw.sound0);
mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.release();
});
mp.setOnErrorListener(new OnErrorListener(){
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
mMp.release();
return false;
}
});
mp.start();
Greets Klaus
On 18 Jan., 14:31, Breezy <[email protected]> wrote:
> I'm writing a program for my toddler and I'm running into a problem.
>
> I call mediaplayer numerous times. Each time a button is clicked it
> runs media player, but it's a different sound. So should I create a
> new instance each time?
>
> Here's what I'm looking at...
>
> if(buttonClicked == button1)
> {
> MediaPlayer mp =
> MediaPlayer.create(getBaseContext(),
> R.raw.sound0);
> mp.start();
> mp.release();
> }
> else if(buttonClicked == button2)
> {
> MediaPlayer mp =
> MediaPlayer.create(getBaseContext(),
> R.raw.sound1);
> mp.start();
> mp.release();
> }
>
> Now that seems to work fine on the emulator. When I pack it up into
> an APK and put it on my G1 I can only do it 7 times before it force
> closes. I BELIEVE the memory gets full or something.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en