Search code examples
androidandroid-mediaplayer

Mediaplayer error (-19,0) after repeated plays


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?


Solution

  • 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();
    
        };
    });