3dphotoshoot

view src/android/MainActivity.java @ 4:38377f54527a

having a whack at the camera api... at least the java crap compiles, we'll try calling it later
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 19 May 2015 06:05:51 +0300
parents 9df99687a2ff
children e31e23ead56f
line source
1 package com.mutantstargoat.photoshoot3d;
3 import android.app.NativeActivity;
4 import android.util.Log;
5 import static android.opengl.GLES20.*;
6 import android.hardware.Camera;
7 import android.hardware.Camera.CameraInfo;
8 import android.graphics.SurfaceTexture;
9 /*
10 import android.os.Bundle;
11 import android.content.Context;
12 import android.hardware.camera2.*;
13 */
15 public class MainActivity extends NativeActivity {
16 private static String tag = "photoshoot3d";
18 public static void foo()
19 {
20 glClearColor(0.2f, 1.0f, 0.3f, 1.0f);
21 }
23 // old camera api (fallback)
24 private static Camera cam;
26 public static int start_video(int texid)
27 {
28 int num_cams = Camera.getNumberOfCameras();
29 Log.i(tag, "Found " + num_cams + " cameras");
31 for(int i=0; i<num_cams; i++) {
32 CameraInfo info = new CameraInfo();
33 Camera.getCameraInfo(i, info);
35 String facing_str = info.facing == CameraInfo.CAMERA_FACING_FRONT ? "front" : "back";
37 Log.i(tag, "camera[" + i + "]: " + facing_str);
38 }
40 SurfaceTexture surftex = new SurfaceTexture(texid);
41 surftex.setOnFrameAvailableListener(new FrameHandler());
43 cam = Camera.open();
44 try {
45 cam.setPreviewTexture(surftex);
46 }
47 catch(java.io.IOException e) {
48 Log.e(tag, "failed to set preview texture");
49 cam = null;
50 return -1;
51 }
52 cam.startPreview();
54 return 0;
55 }
57 public static void stop_video()
58 {
59 cam.stopPreview();
60 cam = null;
61 }
62 }
64 class FrameHandler implements SurfaceTexture.OnFrameAvailableListener {
65 public void onFrameAvailable(SurfaceTexture stex)
66 {
67 stex.updateTexImage();
68 }
69 }