0

I am developing a android application that plays a digital radio. The app was playing the radio but i need to show a ProgressDialog for the user do not to think that the application was stopped.

I do not know how to fix this problem! Before i make the ProgressDialog the app was run correctly. Now the app do not plays the radio! Only shows the ProgressDialog. THANKS!

PS. SORRY FOR MY ENGLISH!

@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();
    }
4

0 回答 0