title: Trigger an event when mediaPlayer stops
body: <p>I am making an app that uses sound effects. I would like to know how i can detect when a sound has finished playing and trigger an event .</p>
  
  <p>i tried this :</p>
  
  <pre><code> player = new MediaPlayer();
      if (player != null) {
          player.reset();
          player.release();
      }
  
      player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
          @Override
          public void onCompletion(MediaPlayer mediaPlayer) {
  
              sonar.setBackgroundResource(R.drawable.sonar_off);
              stopPlay();
          }
      });
  
          if(state==1){
              player = MediaPlayer.create(this, R.raw.sonar_slow);
          }else if(state==2){
              player = MediaPlayer.create(this, R.raw.sonar_medium);
          }else if(state==3){
              player = MediaPlayer.create(this, R.raw.sonar_fast);
          }
           try{
               player.prepare();
              } catch (IllegalStateException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
              } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
              } 
          player.start();
  </code></pre>