I am trying to create a music streaming app. So far it works just fine. I am using the
MediaPlayer.create(thisContext, Uri.parse(PATH_TO_STREAM));
convenience method to prepare the infinite stream (24x7 mp3 stream). It hangs for just a few seconds on this call which I have neatly tucked into my startPlaying() method. The button doesn't show it's getting clicked until after the stream starts playing so at first the user is left wondering if they tapped the button or missed. So I want to update a TextView label next to the button that says "Wait..." or "Buffering" etc. then clear it after the stream starts so the user knows they pressed the button OK. Even if I step through this in debug the label doesn't update until after the onClick is finished. I can comment out the last line that clears the label text and can see it set to "Buffering..." OK. But only after it exits the onClick. Is this a limitation of using the media player create() method?
final Button startbutton = (Button) findViewById(R.id.Button01);
this.tvBuffering = (TextView) findViewById(R.id.tvBuffering);
startbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
tvBuffering.setText("Buffering...");
//do something like invalidate() here??
startPlaying(); //blocks here for a few seconds to buffer then plays.
tvBuffering.setText(" "); //clear the text since it's playing by now.
}
});