title: Wait for a sound to end playing. Is this correct?
body: <p>In my application I need to play a sound in different moments and wait for it to end before doing anything else. Right now I have this code for playing sound:</p>
  
  <pre><code>private MediaPlayer mPlayer = null;
  private boolean playSound(){
      mPlayer = new MediaPlayer();
      try{
          mPlayer.setDataSource(openFileInput(fileName).getFD());
          mPlayer.prepare();
          mPlayer.start();
      } catch (Exception e){
          e.printStackTrace();
          Log.e("player", "error playing sound: "+fileName);
          return false;
      }
  
      while(mPlayer.isPlaying());
      mPlayer.release();
      mPlayer = null;
      return true;
  }
  </code></pre>
  
  <p>It's not working as I expected: when changing an image before playing the sound the change happens after the sound is played (I suppose it's for the thread queue or something like this)</p>
  
  <p>I don't know if this is a bad solution or if there is any better solution for my case:</p>
  
  <ul>
  <li>the sound playing must start after all previous work is finished.</li>
  <li>the app must not do any other work while playing the sound.</li>
  <li>the code to execute after the sound playing is not always the same.</li>
  </ul>