我正在开发一个播放数字广播的Android应用程序。该应用程序正在播放收音机,但我需要为用户显示ProgressDialog,不要认为应用程序已停止。
我不知道如何解决这个问题!在我制作ProgressDialog之前,应用程序运行正常。现在应用程序不播放收音机!仅显示ProgressDialog。谢谢!
PS。对我的英语抱歉!
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
tx = (TextView) findViewById(R.id.txt);
play = (Button) findViewById(R.id.PLAY);
play.setOnClickListener(this);
//mHandler = new Handler();
}
public void onClick (View v)
{
if (v ==play )
{
dialogo = ProgressDialog.show(this, "Radio Digital CEIZS", "Conectando-se à rádio..", false, true);
dialogo.setCancelable(false);
try
{
playAudio();
}
catch (Exception e) {
e.printStackTrace();
tx.setText("Deu ruim!");
dialogo.dismiss();
}
}
//Bundle extras = getIntent().getExtras();
}
private void playAudio() {
new Thread() {
@Override
public void run() {
try {
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(path);
tx.setText("Play! 3");
mMediaPlayer.prepare();
tx.setText("Play! 4");
mMediaPlayer.start();
dialogo.dismiss();
}
catch (Exception e)
{
e.printStackTrace();
dialogo.dismiss();
}
}
}.start();
}