Mediaplayer error (-19,0) after repeated plays

Mick picture Mick · Mar 27, 2012 · Viewed 23.8k times · Source

I have a game in which a sound plays when a level is completed. Everything works fine to start with but after repeating a level 10 or 20 times the logcat suddenly reports: "MediaPlayer error (-19,0)" and/or "MediaPlayer start called in state 0" and the sounds are no longer made.

I originally had the all sounds in mp3 format but, after reading that ogg may be more reliable, I converted them all to ogg, but the errors appeared just the same.

Any idea how I can fix this problem?

Answer

Gabriel Kaffka picture Gabriel Kaffka · Apr 19, 2013

I was getting the same problem, I solved it by adding the following code to release the player:

mp1 = MediaPlayer.create(sound.this, R.raw.pan1);
mp1.start();
mp1.setOnCompletionListener(new OnCompletionListener() {
    public void onCompletion(MediaPlayer mp) {
        mp.release();

    };
});