MediaPlayer: Stop , play back issue

by AndroidUser » Fri, 06 Mar 2009 05:13:42 GMT


Sponsored Links
 When i tried to play the audio button i can ablet to play, pause.

But i am unable to play again once if i stopped. What i did mistake
here could u plz explain



public class PlayAudio extends Activity {

      /** Called when the activity is first created. */

      @Override

      public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

            final MediaPlayer mp = MediaPlayer.create(getBaseContext
(),

                        R.raw.sunday);



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



            btnPlayAudio.setOnClickListener(new OnClickListener()



            {

                  public void onClick(View v) {

                        if (v.getId() == R.id.btnPlayAudio)
{

                              try {

                                    mp.start
();

                              } catch (Exception e) {

                              }

                        }

                  }



            });



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

            pausePlayAudio.setOnClickListener(new OnClickListener() {

                  public void onClick(View v) {

                        if (v.getId() == R.id.pausePlayAudio) {

                              mp.pause();

                        }

                  }

            });



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

            stopPlayAudio.setOnClickListener(new OnClickListener() {

                  public void onClick(View v) {

                        if (v.getId() == R.id.stopPlayAudio) {

                              mp.stop();

                              mp.release();

                        }

                  }

            });









      }



}


--~--~---------~--~----~------------~-------~--~----~



MediaPlayer: Stop , play back issue

by Marco Nelissen » Fri, 06 Mar 2009 05:33:11 GMT


 It's because you called MediaPlayer.stop() and MediaPlayer.release(),
which stop playback and clean up all resources associated with the
MediaPlayer. You cannot use the MediaPlayer again after release().






--~--~---------~--~----~------------~-------~--~----~


Sponsored Links