title: Show Progress Bar while audio file is Playing?
body: <p>hope finding a solution to my problem , so I have a progress bar showing when clicking on ListView item and while audio file is playing , the problem is when the audio file finish playing the app crashes and gives me this error in logcat:</p>
  
  <blockquote>
    <p>12-11 14:32:17.330 6190-6216/com.example.android.app E/AndroidRuntime: FATAL EXCEPTION: Thread-2
        Process: com.example.android.app, PID: 6190
        java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.media.MediaPlayer.isPlaying()' on a null object reference
            at com.example.android.app.MainActivity$4.run(MainActivity.java:371)
            at java.lang.Thread.run(Thread.java:764)</p>
  </blockquote>
  
  <p>here's the code for the progress bar :</p>
  
  <pre><code> Runnable _progressUpdater;
  private void createProgressParentThread() {
  
      _progressUpdater = new Runnable() {
          @Override
          public void run() {
  
              while(mMediaPlayer.isPlaying()) {
                  try
                  {
                      int current = 0;
                      int total = mMediaPlayer.getDuration();
                      progressBarParent.setMax(total);
                      Log.d("ThangTB", "total:"+total);
                      progressBarParent.setIndeterminate(false);
  
                      while(mMediaPlayer!=null  &amp;&amp; current&lt;total){
                          try {
                              Thread.sleep(200); //Update once per second
                              current = mMediaPlayer.getCurrentPosition();
                              //Removing this line, the track plays normally.
                              progressBarParent.setProgress(current);
                          } catch (InterruptedException e) {
  
                          } catch (Exception e){
  
                          }
                      }
                  }
                  catch(Exception e)
                  {
                      //Don't want this thread to intefere with the rest of the app.
                  }
              }
              if (!mMediaPlayer.isPlaying()) {
                  try {
                      Log.d("ThangTB", "callllllllllllllllll");
                      GONELAYOUT();
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          }
      };
      Thread thread = new Thread(_progressUpdater);
      thread.start();
  }
  
  
  public void GONELAYOUT(){
      this.runOnUiThread(new Runnable() {
  
          @Override
          public void run() {
              // TODO Auto-generated method stub
              progressBarParent.setProgress(0);
              linearLayout_contentProgress.setVisibility(View.GONE);
          }
      });
  }
  
  public void VISIBLELAYOUT(){
      this.runOnUiThread(new Runnable() {
  
          @Override
          public void run() {
              // TODO Auto-generated method stub
              progressBarParent.setProgress(0);
              linearLayout_contentProgress.setVisibility(View.VISIBLE);
          }
      });
  }
  </code></pre>
  
  <p>and I call these method inside the onItemClick :</p>
  
  <pre><code>                mMediaPlayer.start();
                  VISIBLELAYOUT();
                  createProgressParentThread();
  </code></pre>