I would recommend looking into using AsyncTask to do this (http:// developer.android.com/reference/android/os/AsyncTask.html).
You can check against your mp.isPlaying() in the doInBackground portion, use a sleep for some appropriate amount of time if it is still playing (else finish the task), and in onProgressUpdate you can change your color. You can use publishProgress(i); from your doInBackground to pass the iterated color value to your onProgressUpdate to achieve to same color switch functionality you originally wanted. AsyncTask takes a bit to learn, but you'll be glad to have it later! On Aug 9, 11:54 am, androidom <[email protected]> wrote: > Hi there, > I am trying to set the background dynamically as I play music. > > 1) I am able to set the background using the setBackground > (Color.GREEN) method. > 2) Then I play a MP3 file (audio) using the MediaPlayer. > 3) when I call myPlayer().isPlaying(), I would like to keep changing > the background color continiously till the music stops. I tried this > way, > > setContentView(R.layout.main); > //startStreamingAudio(); > tv = new TextView(this); > tv.setBackgroundColor(Color.GREEN); > tv.setTextColor(Color.WHITE); > tv.setText("Do you hear me!"); > setContentView(tv); > mp = MediaPlayer.create(getApplicationContext(), > R.raw.organ_1); > mp.start(); > while(mp.isPlaying()){ > i += 20; > tv.setBackgroundColor(Color.rgb(i, 100, 100)); > setContentView(tv); > } > > It changes only at the end of the sound file. Can someone help me find > the right way towards this ? > thanks > Di --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

