我有一个应用程序来获取带有表面的相机预览帧。它在 Android 4.0.4 上运行,但在更新后不能在同一设备上与 Jelly Bean 4.1.2 一起运行。简单地说,回调永远不会被回调。这是代码: 剪掉一点:
public class Panel extends Activity {
Camera myCamera;
int cameraId = -1;
MyCameraSurfaceView myCameraSurfaceView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_panel);
myCamera = getCameraInstance();
myCamera.setPreviewCallback(new Camera.PreviewCallback() {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
Log.d("Camera Preview", data.length + "");
}
});
myCameraSurfaceView = new MyCameraSurfaceView(this, myCamera);
FrameLayout myCameraPreview = (FrameLayout) findViewById(R.id.videoview);
myCameraPreview.addView(myCameraSurfaceView);
}
private Camera getCameraInstance() {
Camera c = null;
try {
c = Camera.open();
} catch (Exception e) {
e.printStackTrace();
}
return c;
}
public class MyCameraSurfaceView extends SurfaceView implements
SurfaceHolder.Callback {
private SurfaceHolder mHolder;
private Camera mCamera;
public MyCameraSurfaceView(Context context, Camera camera) {
super(context);
mCamera = camera;
mHolder = getHolder();
mHolder.addCallback(this);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
mCamera.setPreviewDisplay(holder);
mCamera.startPreview();
} catch (IOException e) {
}
}
}
}
视频帧正在活动中显示,所以我无法弄清楚我做错了什么。