Skip to content

Commit d07b8c4

Browse files
committed
Implement available() and handleSetSurfaceTexture mthods
Signed-off-by: Umair Khan <[email protected]>
1 parent 1dbe5da commit d07b8c4

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/in/omerjerk/processing/video/android/Capture.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package in.omerjerk.processing.video.android;
22

3+
import java.io.IOException;
34
import java.nio.IntBuffer;
45
import java.util.ArrayList;
56
import java.util.List;
@@ -57,6 +58,8 @@ public static void log(String log) {
5758
IntBuffer frameBuffers = IntBuffer.allocate(1);
5859
IntBuffer renderBuffers = IntBuffer.allocate(1);
5960
IntBuffer customTexture = IntBuffer.allocate(1);
61+
62+
private boolean isAvailable = false;
6063

6164
public Capture(PApplet context) {
6265
this(context, -1, -1);
@@ -111,9 +114,14 @@ public void start() {
111114
mCameraHandler.sendMessage(mCameraHandler.obtainMessage(
112115
CameraHandler.MSG_START_PREVIEW));
113116
}
117+
118+
public boolean available() {
119+
return isAvailable;
120+
}
114121

115122
public void pause() {
116123
log("pause called");
124+
isAvailable = false;
117125
if (mCamera != null) {
118126
mCamera.release();
119127
}
@@ -242,7 +250,13 @@ public static void printCompatibleResolutionsList(Capture capture) {
242250
}
243251

244252
@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+
}
246260

247261
@Override
248262
public void startCamera(Integer cameraId) {
@@ -269,22 +283,13 @@ public void stopCamera() {
269283

270284
@Override
271285
public void startPreview() {
272-
273286
if (applet.getSurfaceHolder().getSurface() == null) {
274287
// preview surface does not exist
275288
return;
276289
}
277290

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-
285291
// start preview with new settings
286292
try {
287-
mCamera.setPreviewTexture(mSurfaceTexture);
288293
mCamera.startPreview();
289294
log("Started the preview");
290295
} catch (Exception e) {
@@ -299,7 +304,8 @@ public void onFrameAvailable(final SurfaceTexture surfaceTexture) {
299304
glView.queueEvent(new Runnable() {
300305
@Override
301306
public void run() {
302-
System.out.println("onFrameAvailable");
307+
log("onFrameAvailable");
308+
isAvailable = true;
303309
surfaceTexture.updateTexImage();
304310

305311
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffers.get(0));

0 commit comments

Comments
 (0)