Home How to use same button after setoncompletitionlistener?
Reply: 0

How to use same button after setoncompletitionlistener?

user957 Published in May 20, 2018, 11:38 am

After I set oncompletetionlistener for MediaPlayer. Using the same button again after the mediaplayer is release, it crashes the app. How do I call a event to play audio after the media player is release?

public class MainActivity extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {

    Button bt1 = findViewById(R.id.b1);
    final MediaPlayer mp1 = MediaPlayer.create(this, R.raw.button1);
    bt1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mp1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                public void onCompletion(MediaPlayer mp) {

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308487 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO