简体   繁体   中英

mp audio stops playing after certain amount of plays

I have a button that plays an mp3, but after too many clicks, the mp3 doesn't start anymore. I'm guessing this has something to do with memory running out, so how do you destroy the mp after each play is finished?

if (mp != null) {
                        mp.stop();
                        mp.release();
                    }
                    mp = MediaPlayer.create(this, R.raw.fart6);
                    mp.start();

I used this

 mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

                        @Override
                        public void onCompletion(MediaPlayer mp) {
                            mp.stop();
                            mp.release();

                        }
                    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM