我希望在oncreat完成时放入进度条...它需要大约10秒的时间来进行策略活动并显示View并准备媒体播放器...... 我可以用什么来显示进度条,直到它显示视图和准备媒体播放器.. 如果有任何教程视频,请你发表评论
@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 :(得分:0)
之后
mediaPlayer = new MediaPlayer();
添加此代码
ProgressDialog pd = new ProgressDialog(this);
pd.setMessage("your message");
pd.setCancelable(false);
pd.setIndeterminate(true);
//Show Dialog
pd.show();
如果您想取消或删除Dialog,只需致电pd.dismiss();