mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
handle no camera detected better
This commit is contained in:
parent
4a7b0b20ad
commit
9e869ae69b
1 changed files with 7 additions and 1 deletions
|
@ -18,6 +18,7 @@ import javafx.scene.image.Image;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class WebcamService extends ScheduledService<Image> {
|
public class WebcamService extends ScheduledService<Image> {
|
||||||
|
@ -47,7 +48,12 @@ public class WebcamService extends ScheduledService<Image> {
|
||||||
protected Image call() throws Exception {
|
protected Image call() throws Exception {
|
||||||
try {
|
try {
|
||||||
if(cam == null) {
|
if(cam == null) {
|
||||||
cam = Webcam.getWebcams(1, TimeUnit.MINUTES).get(0);
|
List<Webcam> webcams = Webcam.getWebcams(1, TimeUnit.MINUTES);
|
||||||
|
if(webcams.isEmpty()) {
|
||||||
|
throw new UnsupportedOperationException("No camera available.");
|
||||||
|
}
|
||||||
|
|
||||||
|
cam = webcams.get(0);
|
||||||
cam.setCustomViewSizes(resolution.getSize());
|
cam.setCustomViewSizes(resolution.getSize());
|
||||||
cam.setViewSize(resolution.getSize());
|
cam.setViewSize(resolution.getSize());
|
||||||
if(!Arrays.asList(cam.getWebcamListeners()).contains(listener)) {
|
if(!Arrays.asList(cam.getWebcamListeners()).contains(listener)) {
|
||||||
|
|
Loading…
Reference in a new issue