Question

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

        }
Was it helpful?

Solution

use following line

 progress = ProgressDialog.show(getActivity(), "dialog title",
                            "dialog message", true);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top