Why is MediaPlayer playing before TextView setText takes effect?

by Breezy » Tue, 19 Jan 2010 10:41:12 GMT


Sponsored Links
 When a button is clicked the text of a textview changes and a sound is
played, but the sound is played first then the text changes.  I would
like it to happen simultaneously if not then the text to take effect
first.  Here's my code...



        public void playSound(int playingFile)
        {
                        MediaPlayer mp = MediaPlayer.create(getBaseContext(), 
playingFile);
                            mp.start();
                            while(mp.isPlaying())
                            {
                                //i put this in so the mp isn't released in 
middle of the
sound
                            }
                        mp.release();
        }

        public void onClick(View v)
        {
                if(v==button1)
                {

                                maintext.setText("2");
                                maintext.setTextColor(Color.RED);
                                playSound(R.raw.s2);
                }
         }


Can anyone see the problem?  It works, just not as I hoped.  Is there
any way this could be more efficient as well?



Other Threads

1. Ga bisa download dari market setelah di root! apa ada pengaruhnya?

om mau tanya....

saya pengguna HTC MAGIC 32A

kenapa saya abis root,ko ga bs download dari market yah?

apa ngaruh?

apa harus ada yang di setting?

udh di reset....

udah coba via wifi dan juga udh coba via APN,tapi terus aja starting
download,tapi ga download...

coba download dari i-music lancar download lagu,tapi download dari
market ga bisa....

saya di Root minggu kemaren kurang lebih,tapi baru dicoba hari ini....

kenapa yah?

apa ada yang harus di setting ulang?

-- 
"Indonesian Android Community [id-android]" 

2. How to customize onscreen keyboard? Please help!

Hi All!

I need to hide all keys except numbers, point and dash and change the
dash behaviour.

Unfortunately attribute android:inputType="number|numberSigned|
numberDecimal" doesn't hide @, #, $ etc. keys.

How can I customize the soft keyboard view? I actually need to show
and react to my custom view. What is is the fast and right way to
implement it?

Please advise some example or code snippets helps to move forward.

Thanks in advance,
Evgeny

-- 

3. Ask Sopwer

4. Unexpected MEDIA_BUTTON action broadcasting when unplugging headset

5. Use of intents

6. How to control alsa's volume

7. Android Database