public synchronized void init() {
   playerIndex = 0;
   activeMediaPlayer = null;
   missionLog.clear();
   missionActivity.clearMissionLog();
   stopWatch.reset();
 }
  public synchronized void start() {
    // Clear the mission introduction when the mission is started (not resumed after a pause)
    if (stopWatch.missionTimeInNanos() == 0) {
      missionLog.clear();
      missionActivity.clearMissionLog();
    }
    if (mediaPlayerList.size() <= playerIndex) {
      init();
    }

    stopWatch.start();

    stopped = false;
    if (paused) {
      paused = false;

      // Even when a running sound was paused, you have to update the
      // startTime for the next file
      startTime += System.nanoTime() - timeWhenPaused;

      if (activeMediaPlayer == null) {
        mediaPlayerBackgroundSounds.start();
      } else {
        activeMediaPlayer.start();
      }
      if (activeMediaPlayer == null || activeMediaPlayer.isLooping()) {
        postAtTime(
            mPlayNextAudioTask, startTime + mediaPlayerList.get(playerIndex).getStartTimeNanos());
      }
      return;
    }

    startTime = System.nanoTime();
    playNextAudio();
  }
  private void updateMissionLog(final MediaInfo mediaInfo) {
    if (!TextUtils.isEmpty(mediaInfo.toString())) {
      boolean bLogColors = preferences.getBoolean("logColorsPreference", true);

      StringBuilder timeText = new StringBuilder();
      StringBuilder actionText = new StringBuilder();

      // Display log in colors (if preference is set to true)
      // Note: Some parts are now bold, regardless of the color settings
      // (Time, Unconfirmed, Serious - like the printed cards)
      if ((mediaInfo.getTimeColor() == null) || (bLogColors == false)) {
        timeText.append("<b>" + stopWatch.toString() + "</b>");

      } else {
        timeText.append(
            "<b><font color=\""
                + mediaInfo.getTimeColor()
                + "\">"
                + StopWatch.formatTime(mediaInfo.getStartTimeNanos())
                + "</b></font>");
      }

      if ((mediaInfo.getTimeColor() == null) || (bLogColors == false)) {
        actionText.append(mediaInfo.toString());
      } else {
        actionText.append(
            "<font color=\"" + mediaInfo.getTextColor() + "\">" + mediaInfo.toString() + "</font>");
      }

      missionLog.add(
          new MissionLog(Html.fromHtml(actionText.toString()), Html.fromHtml(timeText.toString())));
      missionActivity.updateMissionLog(missionLog.size() - 1);
    }
  }
 @Override
 public synchronized void stop() {
   super.stop();
   missionActivity.toggleOff();
   mediaPlayerBackgroundSounds.stop();
   stopWatch.stop();
   timerHandler.removeCallbacks(mPlayNextAudioTask);
 }
 @Override
 public synchronized void pause() {
   super.pause();
   stopWatch.pause();
   mediaPlayerBackgroundSounds.pause();
   missionActivity.toggleOff();
   timeWhenPaused = System.nanoTime();
   timerHandler.removeCallbacks(mPlayNextAudioTask);
 }
 /*
  * Prints the mission introduction to the log.
  */
 public void printMissionIntroduction(String missionIntroduction) {
   missionLog.add(new MissionLog(Html.fromHtml("<b><i> " + missionIntroduction + "</i></b>")));
   missionActivity.updateMissionLog(missionLog.size() - 1);
 }