tazeen
tazeen

Reputation: 145

How to disable another button when sound clip is over in Android?

I'm implementing Android application for creating media player.I have run the application properly for playing the music on button click . When i click the button_Start the music is start to playing and click on the same button_Start for pause and resume/start.when the button_Start is click my button_Second is disable and when button_Start click for pause then button_Second is disable is properly . But I want when sound clip is over my button_Second is enable and button_Start is disabled .I'm getting error when i run the app (IllegelStateException) . I don't know how can i do this.Can any one help me.Thanks in advanced.

Here is my code .This is y Audio_Activity class.

public class Audio_Activity extends Activity
{
    private  MediaPlayer mp;
    Button btnStartStop ;
    Button btnChapter ;


    ImageView imgVw;
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.audio);
        init();


        mp=MediaPlayer.create(this,R.raw.ennamo_yadho);
        Log.e("Song is playing","in  Mediya Player ");

        System.out.println("B4 button Click!!!!");


        System.out.println("After Button click !! ");
        if(mp!=null)
        {
            mp.stop();
            mp.release();
            System.out.println("Media Player Is Stop and release");

            btnChapter.setEnabled(true);
            System.out.println("btnChapter is enabled when media player is 
                         release !!!");

        }

        btnStartStop.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View arg0) 
            {
                // TODO Auto-generated method stub

                if(mp.isPlaying())
                {
                    if(mp!=null)
                    {
                            mp.pause();
                        imgVw.setImageResource(R.raw.images1);
                        btnChapter.setEnabled(true);

                    }
                }

                else
                {
                    // Resume song
                    if(mp!=null)
                    {
                            mp.start();
                        imgVw.setImageResource(R.raw.teddy_two);
                        btnChapter.setEnabled(false);


                    }


            }}
        });



    }


    public void init()
    {
        imgVw=(ImageView)findViewById(R.id.display_Images);


        btnStartStop=(Button) findViewById(R.id.btnPause_Resume);
        btnChapter=(Button) findViewById(R.id.btnChapter);


    }

}

Upvotes: 0

Views: 135

Answers (1)

AggelosK
AggelosK

Reputation: 4351

You can disable the button when the sound clip starts and then use the setOnCompletionListener method of the MediaPlayer class (link) to register a handler that will enable the button again. Hope that helps:)

Upvotes: 1

Related Questions