1
1
package in .omerjerk .processing .video .android ;
2
2
3
+ import java .io .IOException ;
3
4
import java .nio .IntBuffer ;
4
5
import java .util .ArrayList ;
5
6
import java .util .List ;
@@ -57,6 +58,8 @@ public static void log(String log) {
57
58
IntBuffer frameBuffers = IntBuffer .allocate (1 );
58
59
IntBuffer renderBuffers = IntBuffer .allocate (1 );
59
60
IntBuffer customTexture = IntBuffer .allocate (1 );
61
+
62
+ private boolean isAvailable = false ;
60
63
61
64
public Capture (PApplet context ) {
62
65
this (context , -1 , -1 );
@@ -111,9 +114,14 @@ public void start() {
111
114
mCameraHandler .sendMessage (mCameraHandler .obtainMessage (
112
115
CameraHandler .MSG_START_PREVIEW ));
113
116
}
117
+
118
+ public boolean available () {
119
+ return isAvailable ;
120
+ }
114
121
115
122
public void pause () {
116
123
log ("pause called" );
124
+ isAvailable = false ;
117
125
if (mCamera != null ) {
118
126
mCamera .release ();
119
127
}
@@ -242,7 +250,13 @@ public static void printCompatibleResolutionsList(Capture capture) {
242
250
}
243
251
244
252
@ Override
245
- public void handleSetSurfaceTexture (SurfaceTexture st ) {}
253
+ public void handleSetSurfaceTexture (SurfaceTexture st ) {
254
+ try {
255
+ mCamera .setPreviewTexture (mSurfaceTexture );
256
+ } catch (IOException e ) {
257
+ e .printStackTrace ();
258
+ }
259
+ }
246
260
247
261
@ Override
248
262
public void startCamera (Integer cameraId ) {
@@ -269,22 +283,13 @@ public void stopCamera() {
269
283
270
284
@ Override
271
285
public void startPreview () {
272
-
273
286
if (applet .getSurfaceHolder ().getSurface () == null ) {
274
287
// preview surface does not exist
275
288
return ;
276
289
}
277
290
278
- // stop preview before making changes
279
- try {
280
- mCamera .stopPreview ();
281
- } catch (Exception e ) {
282
- // ignore: tried to stop a non-existent preview
283
- }
284
-
285
291
// start preview with new settings
286
292
try {
287
- mCamera .setPreviewTexture (mSurfaceTexture );
288
293
mCamera .startPreview ();
289
294
log ("Started the preview" );
290
295
} catch (Exception e ) {
@@ -299,7 +304,8 @@ public void onFrameAvailable(final SurfaceTexture surfaceTexture) {
299
304
glView .queueEvent (new Runnable () {
300
305
@ Override
301
306
public void run () {
302
- System .out .println ("onFrameAvailable" );
307
+ log ("onFrameAvailable" );
308
+ isAvailable = true ;
303
309
surfaceTexture .updateTexImage ();
304
310
305
311
GLES20 .glBindFramebuffer (GLES20 .GL_FRAMEBUFFER , frameBuffers .get (0 ));
0 commit comments