There was a similar problem discussed a few days back, except that a
TextView was to be updated.

Check out the source code here.
http://groups.google.com/group/android-beginners/browse_thread/thread/2e614021697d15e/ec3bc0bce37cb3ef?q=handler#ec3bc0bce37cb3ef

If you still have problems, post your specific question here.

Balwinder Kaur
Open Source Development Center
·T· · ·Mobile· stick together

The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.

On Aug 12, 3:54 pm, chinchin <nchinn...@googlemail.com> wrote:
> Hello,
> I have created a MediaPlayer and will play a sound file. There is also
> a ProgressBar which I've configured to be a Horizontal Progress Bar.
> The problem I'm having is getting the progress bar to update as the
> song plays, i.e. when the song is half way played I want the progress
> bar to be half way filled.
> I can see that the trick is to use some sort of sleeping thread that
> wakes up and then performs the ProgressBar.setProgress
> (MediaPlayer.getCurrentPosition()) code but I cannot factor in the
> threading code.
> Would someone please take a look at a simple version of my code that
> uses a button to manually update the progress bar and please help to
> set me on the right course. Threads have never been my strong suit :(
> Thanks in advance guys.
>
> public class musicPlayer extends Activity {
>
>         private Button buttonPlay;
>         private MediaPlayer mp = new MediaPlayer();
>         private ProgressBar progressMusic;
>
>         /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>
>         initialiseSong();
>
>         //Create Play Button
>         buttonPlay = (Button) findViewById(R.id.buttonPlay);
>         buttonPlay.setOnClickListener(new OnClickListener(){
>                 public void onClick(View v){
>                         playSong();
>                 }
>         });
>
>         progressMusic = (ProgressBar) findViewById
> (R.id.progressMusic);
>         progressMusic.setProgress(0);
>         progressMusic.setMax(mp.getDuration());
>
>         final Button buttonIndex = (Button) findViewById
> (R.id.buttonIndex);
>         buttonIndex.setOnClickListener(new OnClickListener(){
>                 public void onClick(View v){
>                         progressMusic.setProgress(mp.getCurrentPosition());
>                 }
>         });
>     }
>
>     //Creates the player with a default song selected.
>     private void initialiseSong(){
>         mp = MediaPlayer.create(this, R.raw.cake);
>     }
>     private void playSong(){
>                 if(mp.isPlaying()){
>                         mp.pause();
>                         buttonPlay.setText("Resume");
>                 }else{
>                         mp.start();
>                         buttonPlay.setText("Pause");
>                 }
>     }
>
> }
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to