[英]Progress dialog not showing up while media controller loading the sound file
I'm using a media controller and media player to load a sound file from a server. 我正在使用媒体控制器和媒体播放器从服务器加载声音文件。 I want to display a progress dialog box while the it is loading the sound file.
我要在加载声音文件时显示一个进度对话框。 The problem is actually the progress car shows but not as soon as I presses the button but just before the media controller shows up it shows and hides immediately .
问题实际上是进度车显示出来的,但不是我按下按钮时就显示,而是在媒体控制器出现之前就显示并立即隐藏。 The media controller is working fine.
介质控制器工作正常。
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();
}
});
I'm stopping the progress dialog as follows: 我将停止进度对话框,如下所示:
@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();
}
});
}
use following line 使用以下行
progress = ProgressDialog.show(getActivity(), "dialog title",
"dialog message", true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.