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


Other Threads

1. few question about adb

hi all,

the adb tool shows "offline" somtimes, so I want to review the
relative code about adb.

1. where is the adb relative driver code in the kernel tree?
2. is any updated log about adb tool?
3. is any updated log about adb tool when android sdk updated?

some questions, please give me some suggestion,

thanks!!

-- 

2. Gmail Contacts Groups and Android Contact Groups

Hi,

I am trying to synchronize (import) the gmail contact groups into my android
phone but without success. Is there any trick or way? My phone is Samsung
GALAXY S (GT-I9000) with Android v2.1-update1.


Regards,
Miro.

-- 
.

3. MDPI Android 2.3.1

4. Change Texture

5. Status of Android CTS (Compatibility Test Suite) on froyo-x86 and gingerbread?

6. How can I achieve this menu in android?

7. Access database (in static method?) in non-Activity class