Looking for some guidance: I have a ProgressBar I'm using to track the
progress of a MediaPlayer instance that works in one location but
fails in the other. The specific failure is that all attempts to
change the displayed result (setProgress/setMax) appear to be ignored:
the progress bar ALWAYS displays 0% progress, even though the
getProgress value is not zero. I've duplicated this on Android 1.5
(G1) and Android 2.2 (Nexus 1).

The progress bar is created by inflating a view XML file in a class
that extends Activity: 2 other classes extend this class and are
declared in the manifest. The code that updates the ProgressBar is

void updateAudioProgress(App a, boolean init)
        {
        if(a.getMediaPlayer() == null || audioControlToolbar == null ||
                        (!init && audioControlToolbar.getVisibility() == 
View.GONE))
                return;
                ImageButton ib = (ImageButton)findViewById(R.id.playpause);
                if(a.getMediaPlayer().isDownloading()){
                        ib.setVisibility(View.INVISIBLE);
                        TextView tv = (TextView)findViewById(R.id.duration);
                        tv.setText("");
                        ProgressBar pb = 
(ProgressBar)findViewById(R.id.progress);
                        pb.setMax(5000);
                        pb.setProgress((int)(5000 *
a.checkDownloadProgress(a.getMediaPlayer().getPendingUrl())));
                        Message m = Message.obtain();
                        m.what = App.UPDATE_DOWNLOAD_PROGRESS;
                        getHandler().sendMessageDelayed(m, 1000);
                }else{
                        boolean newAudioState =
a.getMediaPlayer().getPlayer().isPlaying();
                        if(newAudioState != a.getLastAudioState() || init){
                                init = true;
                                if(newAudioState){
        
ib.setImageDrawable(getResources().getDrawable(R.drawable.pause));
                                }else{
                                        
ib.setImageDrawable(getResources().getDrawable(R.drawable.play));
                                }
                        }
                        if(ib.getVisibility() == View.INVISIBLE || init){
        
((TextView)audioControlToolbar.findViewById(R.id.audiocaption)).setText(a.getMediaPlayer().getCaption());
                                ib.setVisibility(View.VISIBLE);
                        }
                        if(init || newAudioState){
                                int dur = 
a.getMediaPlayer().getPlayer().getCurrentPosition();
                                ProgressBar pb = 
(ProgressBar)findViewById(R.id.progress);
                                int max =  
a.getMediaPlayer().getPlayer().getDuration();
                                pb.setMax(max);
                                pb.setProgress(dur);
                                TextView tv = 
(TextView)findViewById(R.id.duration);
                                tv.setText(a.formatDuration(dur - max));
                                
android.util.Log.v("JLA",String.format("[%s/%s]", dur, max));
                        }else{
                                
android.util.Log.v("LISTACTIVITY",String.format("[%s][%s]", init,
newAudioState));
                        }
                        a.setLastAudioState(newAudioState);
                        Message m = Message.obtain();
                        m.what = App.UPDATE_PLAYBACK_PROGRESS;
                        getHandler().sendMessageDelayed(m, 1000);
                }
        }

This is invoked from a handler (as seen at the very bottom of the
function).

I've tried forceLayout(), invalidate(), and postInvalidate() on every
combination of the ProgressBar itself, its hosting View (a
RelativeLayout) and the entire Activity's getContentView(). I can
verify that the values are updating: below is a segment of the device
log:

08-03 23:24:14.717: VERBOSE/JLA(1455): [43310/148032]
08-03 23:24:15.724: VERBOSE/JLA(1455): [43676/148032]
08-03 23:24:16.725: VERBOSE/JLA(1455): [44042/148032]
08-03 23:24:17.729: VERBOSE/JLA(1455): [44407/148032]
08-03 23:24:18.734: VERBOSE/JLA(1455): [44773/148032]
08-03 23:24:19.735: VERBOSE/JLA(1455): [45139/148032]
08-03 23:24:20.738: VERBOSE/JLA(1455): [45505/148032]
08-03 23:24:21.738: VERBOSE/JLA(1455): [45870/148032]
08-03 23:24:22.744: VERBOSE/JLA(1455): [46236/148032]
08-03 23:24:23.744: VERBOSE/JLA(1455): [46602/148032]
08-03 23:24:24.748: VERBOSE/JLA(1455): [46967/148032]
08-03 23:24:25.754: VERBOSE/JLA(1455): [47333/148032]
08-03 23:24:26.756: VERBOSE/JLA(1455): [47699/148032]
08-03 23:24:27.761: VERBOSE/JLA(1455): [48064/148032]
08-03 23:24:28.764: VERBOSE/JLA(1455): [48430/148032]
08-03 23:24:29.768: VERBOSE/JLA(1455): [48770/148032]
08-03 23:24:30.774: VERBOSE/JLA(1455): [49135/148032]
08-03 23:24:31.777: VERBOSE/JLA(1455): [49501/148032]
08-03 23:24:32.774: VERBOSE/JLA(1455): [49867/148032]
08-03 23:24:33.785: VERBOSE/JLA(1455): [50233/148032]
08-03 23:24:34.785: VERBOSE/JLA(1455): [50598/148032]
08-03 23:24:35.787: VERBOSE/JLA(1455): [50964/148032]
08-03 23:24:36.794: VERBOSE/JLA(1455): [51330/148032]
08-03 23:24:37.796: VERBOSE/JLA(1455): [51695/148032]
08-03 23:24:38.798: VERBOSE/JLA(1455): [52061/148032]
08-03 23:24:39.804: VERBOSE/JLA(1455): [52427/148032]
08-03 23:24:40.805: VERBOSE/JLA(1455): [52793/148032]
08-03 23:24:41.805: VERBOSE/JLA(1455): [53158/148032]



I'd appreciate any suggestions or pointers that might shed some light
on this issue.
Thanks,
Femi.

-- 
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

Reply via email to