public void onEvent(javax.media.mscontrol.join.JoinEvent event) {

      MediaGroup mg = (MediaGroup) event.getThisJoinable();
      if (event.isSuccessful()) {

        if (JoinEvent.JOINED == event.getEventType()) {
          // NC Joined to MG

          try {
            Player player = mg.getPlayer();
            player.addListener(new PlayerListener());

            URI prompt = URI.create(WELCOME_MSG);

            player.play(prompt, null, null);

          } catch (MsControlException e) {
            logger.error(e);
          }
        } else if (JoinEvent.UNJOINED == event.getEventType()) {
          if (logger.isDebugEnabled()) {
            logger.debug("Un-Joined MG and NC");
          }
        }

      } else {
        logger.error("Joining of MG and NC failed");
      }
    }
    public void onEvent(PlayerEvent event) {

      Player player = event.getSource();
      MediaGroup mg = player.getContainer();
      if (!isBye) {
        if (event.isSuccessful() && (PlayerEvent.PLAY_COMPLETED == event.getEventType())) {

          MediaSession mediaSession = event.getSource().getMediaSession();

          SipSession sipSession = (SipSession) mediaSession.getAttribute("SIP_SESSION");

          sipSession.setAttribute("MEDIA_GROUP", mg);

          SipApplicationSession sipAppSession = sipSession.getApplicationSession();

          try {
            Recorder recoredr = mg.getRecorder();
            logger.info("recording the user at " + RECORDER);
            URI prompt = URI.create(RECORDER);

            recoredr.record(prompt, null, null);

            TimerService timer = (TimerService) getServletContext().getAttribute(TIMER_SERVICE);
            timer.createTimer(sipAppSession, RECORDING_DELAY, false, sipSession.getId());

          } catch (MsControlException e) {
            logger.error("An unexpected error happened ", e);
          }
        } else {
          logger.error("Player didn't complete successfully ");
        }
      }
    }
  public void onEvent(PlayerEvent event) {
    try {
      logger.info("ENDING CALL ");
      Player player = event.getSource();
      MediaGroup mg = player.getContainer();
      if (event.isSuccessful() && (PlayerEvent.PLAY_COMPLETED == event.getEventType())) {
        MediaSession session = (MediaSession) sipSession.getAttribute("mediaSession");
        session.release();
        Thread.sleep(1500);

        SipServletRequest byeRequest = sipSession.createRequest("BYE");
        byeRequest.send();
      }

    } catch (Exception e) {
      logger.error("Error", e);
    }
  }