Media Player: error (-19, 0)

3.4k views Asked by At

I have a GridView with your positions and I do case on the onCreate, So,

case position = 1 play audio1,

case position = 2 play audio2

The Activity:

public class HomeEnglishAnimalsActivity extends ActionBarActivity {

MediaPlayer player;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home_english_animals);

    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);

    GridView gridView = (GridView) findViewById(R.id.gridviewHomeEnglishAnimals);
    gridView.setAdapter(new AdapterHomeEnglishAnimalsActivity(this));

    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v,
                                int position, long id) {
            switch (position) {
                case 0:
                    if (player != null)
                    {
                        player.stop();
                        player.release();
                    }
                    player.create(HomeEnglishAnimalsActivity.this, R.raw.bee).setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                        @Override
                        public void onPrepared(MediaPlayer mediaPlayer) {
                            mediaPlayer.start();
                        }
                    });
                    break;

Ok, the code works but when I click a few times, the sound stop show this errors:

06-16 23:52:42.976  23918-23918/br.gabrielrossetto.tap4learn E/ExtMediaPlayer-JNI? QCMediaPlayer could not be located....
06-16 23:52:42.976  23918-23918/br.gabrielrossetto.tap4learn E/MediaPlayer-JNI? QCMediaPlayer mediaplayer NOT present
06-16 23:52:42.986  23918-23918/br.gabrielrossetto.tap4learn E/MediaPlayer? Should have subtitle controller already set
06-16 23:52:42.996  23918-23918/br.gabrielrossetto.tap4learn E/MediaPlayer? error (-19, 0)
06-16 23:52:42.996  23918-23918/br.gabrielrossetto.tap4learn E/MediaPlayer? Error (-19,0)

Thanks for your help.

2

There are 2 answers

0
jeet parmar On BEST ANSWER

try this

when you create MediaPlayer object and start player you need to release it when music Complete.

    MediaPlayer mp;
    mp = MediaPlayer.create(getApplicationContext(), R.raw.sound);
    mp.start();

    mp.setOnCompletionListener(new OnCompletionListener() {
        public void onCompletion(MediaPlayer mp) {
            mp.release();

        };
    });

}
0
E. Fernandes On

You need to release the MediaPlayer you are using to play the sound. Check out this thread: Mediaplayer error (-19,0) after repeated plays