Java 准备时无法在mp3媒体播放器上显示ProgressDialog

Java 准备时无法在mp3媒体播放器上显示ProgressDialog,java,android,Java,Android,我有一个媒体播放器,可以从url播放mp3。我想在从url加载音频时显示进度对话框。这是我的密码。。我是新来的,所以如果你不能很好地理解我的问题,请不要介意。提前谢谢 发挥作用 public void playSong(int naatindex){ // Play song tv = (TextView) this.findViewById(R.id.mywidget); tv.setText("Buffering...."); tv.setSelecte

我有一个媒体播放器,可以从url播放mp3。我想在从url加载音频时显示进度对话框。这是我的密码。。我是新来的,所以如果你不能很好地理解我的问题,请不要介意。提前谢谢

发挥作用

public void  playSong(int naatindex){
    // Play song
    tv = (TextView) this.findViewById(R.id.mywidget);  
    tv.setText("Buffering....");
    tv.setSelected(true); 

    final ProgressDialog progressDialog = ProgressDialog.show(this, 
            "Loading Title", "Loading Message");

        mp.setOnPreparedListener(new OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
       if (progressDialog != null && progressDialog.isShowing()){
          progressDialog.dismiss();
       }
        mp.start();
    }
    });
    try {

        mp.reset();
        mp.setDataSource(naatpaths[naatindex]);
        tv = (TextView) this.findViewById(R.id.mywidget);  
        tv.setSelected(true);

        mp.prepare();

         // Set focus to the textview
        tv.setText(naattitles[naatindex]);
        // Changing Button Image to pause image
        btnPlay.setImageResource(R.drawable.btn_pause);
        // set Progress bar values
        songProgressBar.setProgress(0);
        songProgressBar.setMax(100);
        // Updating progress bar
        updateProgressBar();            
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
您必须使用prepareAsync();并创建另一个文本缓冲的文本视图。在prepareAsync()可见缓冲textview时。并在准备好的完整列表器上隐藏缓冲文本视图。我希望这能奏效

public void  playSong(final int naatindex){
// Play song
tv = (TextView) this.findViewById(R.id.mywidget);  
bf = (TextView) this.findViewById(R.id.showbuffering);


try {

mp.reset();
mp.setDataSource(naatpaths[naatindex]);
tv.setVisibility(View.INVISIBLE);
bf.setVisibility(View.VISIBLE);   
mp.prepareAsync();



mp.setOnPreparedListener(new OnPreparedListener(){
@Override
public void onPrepared(MediaPlayer mp){
 bf.setVisibility(View.INVISIBLE);
 tv.setVisibility(View.VISIBLE);
 tv.setSelected(true);
 mp.start();

  tv.setText(naattitles[naatindex]);
        tv.setSelected(true);
        // Changing Button Image to pause image
  btnPlay.setImageResource(R.drawable.btn_pause);
  // set Progress bar values
  songProgressBar.setProgress(o);
  songProgressBar.setMax(100);
  // Updating progress bar
  updateProgressBar(); 




}
  });

      // Set focus to the textview

     } catch (IllegalArgumentException e) {
             e.printStackTrace();
      } catch (IllegalStateException e) {
         e.printStackTrace();
         } catch (IOException e) {
       e.printStackTrace();
     }
  }

谢谢,这是我的工作。谢谢你