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

时间:2015-01-03 15:53:54

标签: java android

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

播放功能

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();
    }
}

1 个答案:

答案 0 :(得分:1)

您必须使用prepareAsync();并创建另一个文本视图,文本正在缓冲。而prepareAsync()可见缓冲textview。并准备完整的lister hide缓冲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();
     }
  }