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. How onCreate/OnDestory method

Hi,

Each activity has a onCreate/OnDestory method. And I think they are
being invoked by frameworks/base/core/java/Instrumentation.java.

My question is what it is process calling
Instrumentation.callActivityOnDestory() and
Instrumentation.callActivityOnStart()?
Does that process has root permission?

Thank you.

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

2. Question about screen lock mechanism

Hi all
There is a screen lock mechanism in SDK emulator, which require you to
press menu key to unlock.
I've seen the mechanism in the open source release after 2009,
however, it is disappeared again in the latest distribution.
Anyone know the reason why? Is there any potential problem or bug in
the screen lock mechanism?

BR
John


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

3. Does the g1 phone gsm modem support AT command to query the state of called phone?

4. Looks like cupcakes on the 1st of May...

5. WebView with theme doesn't show focused text field values

6. How to compile android app with static library?could somebody give me a example?thanks

7. How to Zoom out a picture