title: Loading Dialog on MP3 Media player prepare()
body: <p>I am new one in android development. I have a mp3 audio player code which play mp3 from url. I want to show loading dialog box when media player is buffering on prepare</p>
  
  <p>Here is my Code I show a dialog on prepare but it continuous run and cannot play mp3.
  I have no idea where i define smp.setOnPreparedListener. Please tell me that can i define this in play function or outside play function. Please Help Me here is my code. Thanks in Advance please</p>
  
  <p>//Play MP3 Function </p>
  
  <pre><code>public void  playSong(int naatindex){
      // Play song
      try {
  
          mp.reset();
          mp.setDataSource(naatpaths[naatindex]);
          tv = (TextView) this.findViewById(R.id.mywidget);  
          tv.setSelected(true);  // Set focus to the textview
          tv.setText(naattitles[naatindex]);
          mp.prepare();
          mp.start();
          // Changing Button Image to pause image
          btnPlay.setImageResource(R.drawable.btn_pause);
          // set Progress bar values
          songProgressBar.setProgress(0);
          songProgressBar.setMax(100);
          // Updating progress bar
          updateProgressBar();            
      } catch (IllegalArgumentException e) {
          e.printStackTrace();
      } catch (IllegalStateException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>and here is my mp.setOnPreparedListener code</p>
  
  <pre><code>ProgressDialog progressDialog = ProgressDialog.show(this, 
                          "Loading Title", "Loading Message");
     mp.setOnPreparedListener(new OnPreparedListener() {
      @Override
      public void onPrepared(MediaPlayer mp) {
             if (progressDialog != null &amp;&amp; progressDialog.isShowing()){
                progressDialog.dismiss();
             }
              mp.start();
       }
   });
  </code></pre>