我想在 oncreat 完成时放置进度条...大约需要 10 秒来进行活动并显示查看和准备媒体播放器...我可以用来显示进度条直到它显示视图并准备媒体播放器..如果有的话教程视频请您在评论中发送它
@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();
}} );
}