2013-11-02 79 views
1

我想把進度條,而oncreat完成...它需要大約10秒來開始活動和顯示查看和準備mediaplayer ... 我可以用來顯示進度條,直到它表明的意見和準備的媒體播放器.. 如果有任何視頻教程,請你能不能把它在評論進度條(循環)顯示雖然顯示活動

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.activity_main); 

     final String url = "url"; 

play = (Button)findViewById(R.id.play); 
pause = (Button)findViewById(R.id.pause); 
seekbar = (SeekBar)findViewById(R.id.seekBar1); 
am=(AudioManager)getSystemService(Context.AUDIO_SERVICE); 
int max = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); 
int min = am.getStreamVolume(AudioManager.STREAM_MUSIC); 

seekbar.setMax(max); 
seekbar.setProgress(min); 
seekbar.setOnSeekBarChangeListener(this); 

mediaPlayer = new MediaPlayer(); 


try { 
    mediaPlayer.setDataSource(url); 
} catch (IllegalArgumentException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} catch (SecurityException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} catch (IllegalStateException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} catch (IOException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 
try { 

    mediaPlayer.prepare(); 
} catch (IllegalStateException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} catch (IOException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} // might take long! (for buffering, etc) 



play.setOnClickListener(new OnClickListener(){ 

    @Override 
    public void onClick(View v) { 

      Toast.makeText(getBaseContext(), "text", Toast.LENGTH_LONG).show(); 

    mediaPlayer.start(); 
       }}); 


pause.setOnClickListener(new OnClickListener(){ 

    @Override 
    public void onClick(View v) { 

      mediaPlayer.pause(); 


    }}); 



    } 

回答

0

mediaPlayer = new MediaPlayer();

添加以下代碼

ProgressDialog pd = new ProgressDialog(this); 
     pd.setMessage("your message"); 
      pd.setCancelable(false); 
     pd.setIndeterminate(true); 

      //Show Dialog 
      pd.show(); 

,如果你想取消或刪除對話框只需撥打pd.dismiss();