MediaPlayer errors
<p>I need to write a very simple android application but I have a serious problem.</p>

<p>Here is my class:</p>

<pre><code>package com.music.playa;

import java.util.Random;

import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class PlayMusic extends Activity {

    MediaPlayer mediaPlayer;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void playSound() {

        try {
            mediaPlayer.stop();
            mediaPlayer.reset();
            mediaPlayer.release();
            mediaPlayer = null;         
        } catch (Exception ex) {

        }

        String[] sounds = { "sound1", "sound2", "sound3" };
        mediaPlayer = null;
        int path = getResources().getIdentifier(
                sounds[new Random().nextInt(sounds.length)], "raw",
                getPackageName());
        mediaPlayer = MediaPlayer.create(this, path);

        mediaPlayer
                .setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                    public void onCompletion(MediaPlayer mp) {
                        // do something...
                    }
                });

        mediaPlayer.setVolume(1, 1);
        mediaPlayer.start();

    }

}
</code></pre>

<p>The problem is that when I press the button all the time calling PlaySound function, then after a while (about 40-50 presses of the button), the console throws a lot of errors:</p>

<pre><code>05-28 12:56:00.202: E/MediaPlayer(755): error (-38, 0)
05-28 12:56:01.153: E/MediaPlayer(755): error (-19, 0)
05-28 12:56:01.153: E/MediaPlayer(755): Error (-19,0)
</code></pre>

<p>and the sound stops playing.</p>

<p>What should I do?</p>

<p>Android SDK 2.3.3</p>
