public DrawingEncoder(OutputStream outputStream, Bitmap initialFrame) {
    out = new DataOutputStream(outputStream);
    frameGroup = new DrawingFrameGroup(initialFrame);
    player = new DrawingPlayer();
    player.setCurrentFrame(initialFrame);

    frameGroup.setTimeIndex(0);
  }
 public synchronized void run() {
   try {
     while (true) {
       QueueItem item = queue.takeFirst();
       if (item.timeIndex < 0) {
         frameGroup.encode(out);
         frameGroup = null;
         return;
       }
       if (item.timeIndex - frameGroup.getTimeIndex() >= keyFrameInterval) {
         frameGroup.encode(out);
         frameGroup = new DrawingFrameGroup(player.getCurrentFrame());
         frameGroup.setTimeIndex(item.timeIndex);
       }
       frameGroup.appendFrame(
           new DrawingFrame((short) (item.timeIndex - frameGroup.getTimeIndex()), item.action));
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }