我使用媒体控制器和媒体播放器从服务器加载声音文件。我想在加载声音文件时显示进度对话框。问题实际上是汽车显示的进度,但不是在我按下按钮之后,而是在媒体控制器出现之前显示并立即隐藏。媒体控制器工作正常。
ImageButton soundLoader = (ImageButton)getActivity().findViewById(R.id.lifeObjectSound);
soundLoader.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
progress = ProgressDialog.show(getActivity(), "dialog title",
"dialog message", true);
mediaPlayer = new MediaPlayer();
mediaPlayer.setOnPreparedListener(currentFragment);
mediaController = new MediaController(getActivity());
try {
mediaPlayer.setDataSource("https://dl.dropboxusercontent.com/u/108022472/5041046.mp3");
mediaPlayer.prepare();
} 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();
}
mediaPlayer.start();
}
});
我按如下方式停止进度对话框:
@Override
public void onPrepared(MediaPlayer mp) {
Log.d("media status", "onPrepared");
mediaController.setMediaPlayer(this);
mediaController.setAnchorView(getView());
handler.post(new Runnable() {
public void run() {
mediaController.setEnabled(true);
mediaController.show(0);
progress.dismiss();
}
});
}
答案 0 :(得分:1)
使用以下行
progress = ProgressDialog.show(getActivity(), "dialog title",
"dialog message", true);