3dphotoshoot
view src/android/MainActivity.java @ 6:e31e23ead56f
GAMO TO XRISTO KAI TIN PANAGIA TOU ANDROID
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 21 May 2015 19:03:00 +0300 |
parents | 38377f54527a |
children | 7f6e6eb3d20e |
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 public 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 @Override
66 public synchronized void onFrameAvailable(SurfaceTexture stex)
67 {
68 Log.i(MainActivity.tag, "new video frame");
69 stex.updateTexImage();
70 }
71 }