Fotoapparat: io.fotoapparat.exception.camera.CameraException: Failed to open camera with lens position: io.fotoapparat.characteristic.LensPosition$Back@31c3b8a2 and id: 0
When I open the first time It will work correctly. But after that, I click on other tabs and then open camera screen It will display a blank white screen.
I am using viewPager for that.
How did you initialize FA?
mCameraView = view.findViewById(R.id.camera);
fotoapparat = Fotoapparat.with(getActivity())
.into(mCameraView)
.previewScaleType(ScaleType.CenterCrop)
.logger(new Logger() {
@Override
public void log(String s) {
Log.e("Camera", s);
}
@Override
public void recordMethod() {
}
})
.cameraErrorCallback(new CameraErrorListener() {
@Override
public void onError(CameraException e) {
e.printStackTrace();
fotoapparat.stop();
}
})
.build();
- FA version 2.5.0:
- Devices/APIs affected 19,20,21,22:
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 13
- Comments: 23 (4 by maintainers)
@Diolor thanks for information. Yes it seems it is, because of those reasons. We will continue to use 2.7.0 version, but with Handlers when calling fotoapparat.start(). It passed our tests and seems to work well.
Replacing/ adding fragments with fotoappart object seems to be an issue…
adding/removing fragments works well without Handlers. I think that we should add an example,which would show proper use case with Fragments and launching Fotoapparat from them , because there are more issues with Fragments 😃
Same issue. I have added runnable with delay 200 ms, when starting fotoappart camera. I am really sad that this library does not get any improvements…
hey @wellbranding, do you still experience blank/black screens? Those should have been fixed in 2.7.0 due to a threading issue that we had.
To the lifecycle topic, well…there is no rule of the thumb. Depends your activities and how they work. Usually, start/stop is ok. Others can use resume/pause but camera will be paused in e.g. in split mode. I would avoid onDestroy because the activity GC is not guaranteed.
Same problem, but ONLY on Huawei P9 Lite (Android 7.0). On the other tested devices, the problem does not occur (Huawei P8 Lite, Moto G4, Pixel 2). As mention @wellbranding , short delay before calling
start()
solved this issue.I made a workaround where we just restart the fragment or activity that holds the camera preview on the occurance of this error. It is shabby, but the user does not see a camera-view with an empty preview when the screen is opened after minimization.