我希望展示的使用面類相機電影:爲什麼`UnsupportedOperationException`拋出嘗試將SurfaceView與相機關聯?
SurfaceView view = (SurfaceView) findViewById(R.id.camera_view);
Surface appSurface = view.getHolder().getSurface();
我通過Surface物件到CameraManager API:
CameraManager manager = (CameraManager) this.getSystemService(Context.CAMERA_SERVICE);
manager.openCamera(
manager.getCameraIdList()[0],
new CameraDevice.StateCallback() {
@Override
public void onOpened(CameraDevice camera) {
// Why this line throws an exception?
camera.createCaptureSession(
Collections.singletonList(appSurface),
new CameraCaptureSession.StateCallback() {...},
null);
}
// other @Override methods
...
},
new Handler(getMainLooper())
);
而且收到以下異常:
FATAL EXCEPTION: main
Process: com.google.android.apps.internal.smartcamera.tagger, PID: 8563
java.lang.UnsupportedOperationException: Unknown error -22
at android.hardware.camera2.legacy.LegacyExceptionUtils.throwOnError(LegacyExceptionUtils.java:77)
at android.hardware.camera2.legacy.LegacyCameraDevice.getSurfaceSize(LegacyCameraDevice.java:583)
at android.hardware.camera2.utils.SurfaceUtils.getSurfaceSize(SurfaceUtils.java:68)
看起來,SurfaceUtils類(它是一塊本地c代碼)無法正確讀取Surface尺寸。 爲什麼?
我有他們,這並沒有解決問題。 – mercury0114