Search code examples
javaandroidaudiomedia-player

Android Mediaplayer Error (-19, 0)


I try to replay a sound when I click on a button. But I get the Error (-19, 0) (what ever this means^^)

My code:

final Button xxx = (Button)findViewById(R.id.xxx);

        xxx.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.plop); 
                mp.start();
            }
        });

What is my mistake?


Solution

  • I was getting the same problem, I solved it by adding the following code:

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