2015-01-03 30 views
3

我有一個媒體播放器,MP3播放器從URL。我想在從url加載音頻時顯示進度對話框。這是我的代碼..我是新人,所以如果你不能很好地理解我的問題,請不要介意。在此先感謝無法顯示的MP3媒體播放器ProgressDialog而準備

播放功能

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

必須使用prepareAsync();並創建另一個文本緩衝文本。而prepareAsync()可見緩衝textview。並在準備完整的李斯特隱藏緩衝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(); 
    } 
    } 
+0

謝謝這對我有用。 Thankkkkkkkkkkkksssssssssss –

相關問題