private Thread thread; // TODO move to a dynamic sub class
protected Configuration config;
private int type = 0;
+ private boolean isPaused = false;
AmbientMode() {}
@Override
public void pause() {
- try {
- thread.wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ isPaused = true;
}
@Override
public void resume() {
+ isPaused = false;
thread.notify();
}
stopThread();
}
- public void startThread() {
+ private void startThread() {
thread = new Thread() {
public void run() {
try {
long start = System.currentTimeMillis();
int index = 0;
while (!isInterrupted()) {
+ if (isPaused) {
+ wait();
+ }
LedFrame frame = LedFrame.from(config);
updateFrame(frame, System.currentTimeMillis() - start, index);
updateWithFrame(frame);
Thread.sleep(20);
}
} catch (InterruptedException e) {
+ e.printStackTrace();
}
}
};
thread.start();
}
- public void stopThread() {
+ private void stopThread() {
thread.interrupt();
}
private Thread grabberThread;
private Consumer<VideoFrame> frameConsumer;
private VideoDeviceListener deviceListener;
+ private boolean isPaused = false;
public VideoMode() {
deviceListener = new VideoDeviceListener();
@Override
public void pause() {
- try {
- grabberThread.wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ isPaused = true;
}
@Override
public void resume() {
+ isPaused = false;
grabberThread.notify();
}
try (FrameGrabber grabber = FrameGrabber.from(videoDevice, config)) {
while (!isInterrupted()) {
Optional<VideoFrame> frame = grabber.grabFrame();
+ if (isPaused) {
+ wait();
+ }
if (frameConsumer != null) frame.ifPresent(frameConsumer);
frame.ifPresent(VideoMode.this::onVideoFrame);
// timeIt("frame", grabber::grabFrame);
}
- } catch (IOException e) {
+ } catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}