public synchronized boolean waitForState(int state) {
      switch (state) {
        case Processor.Configured:
          p.configure();
          break;
        case Controller.Realized:
          p.realize();
          break;
        case Controller.Prefetched:
          p.prefetch();
          break;
        case Controller.Started:
          p.start();
          break;
      }

      while (p.getState() < state && !error) {
        try {
          wait(1000);
        } catch (Exception e) {
        }
      }
      // p.removeControllerListener(this);
      return !(error);
    }
Пример #2
0
  /**
   * Callback for controller events. This method is called by the processor whenever state changes.
   *
   * @param event - describes the nature of the state change.
   */
  public synchronized void controllerUpdate(ControllerEvent event) {

    if (event instanceof ConfigureCompleteEvent) {
      // ConfigurationCompleteEvents come after we
      // call configure() and before we can call realize().
      // At this point we can query the controls to figure
      // out what tracks we have.
      // Debug.trace("ConfigureCompleteEvent");
      setHandlers();
      // set content descriptor to null
      // so that the processor can be used as a player
      processor.setContentDescriptor(null);
      // request transition to realized state
      processor.realize();

    } else if (event instanceof RealizeCompleteEvent) {
      // RealizeCompleteEvents come after we call realize() and
      // before we can call start() or do anything else interesting.
      // Debug.trace("RealizeCompleteEvent");
      controlThread.setState(REALIZED | REWOUND);

      // at this point we should be able to access duration
      // we convert it to the vrml convention (-1 for unknown)
      double vrmlDuration;
      Time duration = processor.getDuration();
      if (duration == Duration.DURATION_UNKNOWN || duration == Duration.DURATION_UNBOUNDED) {
        vrmlDuration = -1.0;
      } else {
        vrmlDuration = duration.getSeconds();
      }
      videoHandler.videoStreamDuration(vrmlDuration);

      // finally we call prefetch will will send the first
      // frame to the video handler.
      processor.prefetch();

    } else if (event instanceof StartEvent) {
      controlThread.setState(STARTED); // set STARTED
      controlThread.unsetState(REWOUND); // clear REWOUND
    } else if (event instanceof StopEvent) {
      // includes EndOfMediaEvent, StopByRequestEvent
      controlThread.unsetState(STARTED); // clear STARTED
    } else if (event instanceof MediaTimeSetEvent) {
      controlThread.setState(TIMESET); // notify any waiting thread
    }
  }