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() {
- grabberThread.notify();
+ isPaused = false;
+ synchronized (grabberThread) {
+ grabberThread.notify();
+ }
}
@Override
try (FrameGrabber grabber = FrameGrabber.from(videoDevice, config)) {
while (!isInterrupted()) {
Optional<VideoFrame> frame = grabber.grabFrame();
+ if (isPaused) {
+ synchronized (grabberThread) {
+ 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();
}
}