@Override
  public void donePlaying(DLNAMediaInfo media, DLNAResource resource) {
    // currently only for videofiles
    if (enabledMV && resource.getType() == Format.VIDEO) {
      // get path information
      Path infoFilePath = Paths.get(resource.getSystemName());
      String folderName = infoFilePath.getParent().toString();
      String infoFile = folderName + "/.viewstatus";
      String infoKey = resource.getName();

      // create handler for properties
      Properties props = new Properties();

      double fileViewPercentage = 0;

      try {
        props.load(new FileInputStream(infoFile)); // load the viewinfo file (if any)
        fileViewPercentage = Integer.parseInt(props.getProperty(infoKey, "0"));
      } catch (IOException e) {
        log.error("viewinfo at " + infoFile + " file does not yet exist");
      }

      double playLengthSec = 0; // total length of the file

      /**
       * @TODO: calculation below should work without startdate. Is it possible to get the exact
       * number of seconds the file was stopped?
       */
      playLengthSec = (int) (new Date().getTime() - startDates.poll().getTime()) / 1000;

      double fullLengthSec = media.getDurationInSeconds();

      if (fullLengthSec > 0) {
        double currentFileViewPercentage = (playLengthSec / fullLengthSec) * 100;

        // if the watched percentage is bigger than in the viewinfo file, write it to viewinfo
        if (currentFileViewPercentage > fileViewPercentage) {
          fileViewPercentage = Math.min(100, currentFileViewPercentage);
          props.setProperty(infoKey, Integer.toString((int) fileViewPercentage));

          try {
            props.store(new FileOutputStream(infoFile), null);

            // update the thumbnail
            media.setThumb(null);
            InputFile input = new InputFile();
            input.setFile(((RealFile) resource).getFile());
            media.generateThumbnail(input, resource.getExt(), resource.getType());

          } catch (IOException e) {
            logExeptionError(e);
          }
        }
      }
    }
  }
  @Override
  public void updateThumb(DLNAMediaInfo media, InputFile f) {
    try {
      BufferedImage image = ImageIO.read(new ByteArrayInputStream(media.getThumb()));

      if (image != null) {
        Graphics g = image.getGraphics();
        Path infoFilePath = Paths.get(f.getFile().getPath()); // get path of current file
        String folderName = infoFilePath.getParent().toString(); // get folder
        String infoFile = folderName + "/.viewstatus"; // get get infofilename
        String infoKey = f.getFile().getName(); // get keyname

        Properties props = new Properties();

        try {
          props.load(new FileInputStream(infoFile));
          String viewInfo = "";
          String allViewed = props.getProperty("allviewed", "false");

          // if allview=true is in the infofile, mark media as viewed
          if (allViewed.equals("true")) {
            viewInfo = "viewed";
          } else {
            // get viewing percentage from infofile
            int fileViewPercentage = Integer.parseInt(props.getProperty(infoKey, "0"));
            if (fileViewPercentage != 0) {
              viewInfo = "viewed for " + fileViewPercentage + "%";
            }
          }

          // if info was set, draw it on the thumbnail
          if (viewInfo != "") {
            // draw a senitransparent black bar to increase readability
            g.setColor(new Color(0, 0, 0, 190));
            g.fillRect(0, image.getHeight() - 35, image.getWidth(), 35);

            // draw info
            g.setFont(new Font("Arial", Font.PLAIN, 25));
            g.setColor(new Color(240, 240, 240));
            FontMetrics fm = g.getFontMetrics();
            int viewInfoX = (image.getWidth() - fm.stringWidth(viewInfo)) / 2;
            int viewInfoY = image.getHeight() - 7;
            g.drawString(viewInfo, viewInfoX, viewInfoY);

            ByteArrayOutputStream out = new ByteArrayOutputStream();
            ImageIO.write(image, "jpeg", out);
            media.setThumb(out.toByteArray());
          }
        } catch (IOException e) {
        }
      }
    } catch (IOException e) {
      log.error("Error while updating thumbnail : " + e.getMessage());
    }
  }