@@ -14,18 +14,29 @@ public class Capture extends PImage implements PConstants {
14
14
15
15
private static Context context ;
16
16
17
- private static ArrayList <String > camerasList = new ArrayList <>();
17
+ private static ArrayList <String > camerasList = new ArrayList <String >();
18
18
19
19
private static final String KEY_FRONT_CAMERA = "front-camera-%d" ;
20
20
private static final String KEY_BACK_CAMERA = "back-camera-%d" ;
21
21
22
+ private int selectedCamera = 0 ;
23
+
22
24
public Capture (PApplet context ) {
23
- Capture . context = context ;
25
+ this ( context , null ) ;
24
26
}
25
27
28
+ public Capture (PApplet context , String camera ) {
29
+ Capture .context = context ;
30
+ if (camera == null || camera .equals ("" )) {
31
+ selectedCamera = 0 ;
32
+ } else {
33
+ selectedCamera = camerasList .indexOf (camera );
34
+ }
35
+ }
36
+
26
37
public static String [] list () {
27
38
ensureContext ();
28
- if (context . getPackageManager (). hasSystemFeature ( PackageManager . FEATURE_CAMERA ) ) {
39
+ if (true ) {
29
40
int nOfCameras = Camera .getNumberOfCameras ();
30
41
for (int i = 0 ; i < nOfCameras ; ++i ) {
31
42
Camera .CameraInfo cameraInfo = new Camera .CameraInfo ();
@@ -46,7 +57,10 @@ public static String[] list() {
46
57
47
58
private static void ensureContext () {
48
59
if (context == null ) {
49
- throw new RuntimeException ("Create the instance of Capture class first." );
60
+ context = PApplet .getInstance ();
61
+ if (context == null ) {
62
+ throw new RuntimeException ("Create the instance of Capture class first." );
63
+ }
50
64
}
51
65
}
52
66
}
0 commit comments