title: Better way to implement empty while loop to hold control
body: <p>I am playing audio in background and I want the control of program to stay stand still till the audio playing is over for that I am using empty while loop as follows</p>
  
  <pre><code>while(isPlaying==true){};
  mediaPlayer.stop();
  </code></pre>
  
  <p>as you can see while loop holds program control till audio is playing and after that next instruction is executed. This is working fine but I came to know that this is not a proper way to do this empty-while is expensive I am searching for alternative. Please Help.  </p>