title: How to fade out Mediaplayer in background?
body: <p>I'm making an android studio apk, and while changing activies i want to fade out the song playing from Mediaplayer, but it instead waits for the fade to end and only then move to next activity. How do i make fade out and activity transition at the same time?</p>
  
  <pre><code>    float volume = 1f;
      while (volume &gt; 0f) {
          MainActivity.mediaPlayer.setVolume(volume, volume);
          volume = volume - 0.1f;
          try {
              Thread.sleep(50);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
  
      }
      MainActivity.mediaPlayer.stop();
  </code></pre>