Closed einschneidend closed 6 years ago
Do you mean you have used those both ways?
cameraFragment.takePhotoOrCaptureVideo(
new CameraFragmentResultAdapter() {
@Override
public void onVideoRecorded(String filePath) {
Toast.makeText(getBaseContext(), "onVideoRecorded " + filePath, Toast.LENGTH_SHORT).show();
}
@Override
public void onPhotoTaken(byte[] bytes, String filePath) {
Toast.makeText(getBaseContext(), "onPhotoTaken " + filePath, Toast.LENGTH_SHORT).show();
}
},
String.valueOf(Environment.getExternalStorageDirectory()),
"photo0" + new Random().nextLong());
}
and you have used
cameraFragment.setResultListener(new CameraFragmentResultListener() {
@Override
public void onVideoRecorded(String filePath) {
Intent intent = PreviewActivity.newIntentVideo(MainActivity.this, filePath);
startActivityForResult(intent, REQUEST_PREVIEW_CODE);
}
@Override
public void onPhotoTaken(byte[] bytes, String filePath) {
}
});
I guess it will call both of them, cause you are subscribing to both events.
You have to make some changes in BaseAnncaFragment.java It calls CameraFragmentResultListener twice.
Origin code of onCreate():
...
@Override
public void onPhotoTaken(byte[] bytes, CameraFragmentResultListener callback) {
final String filePath = cameraController.getOutputFile().toString();
if (cameraFragmentResultListener != null) {
cameraFragmentResultListener.onPhotoTaken(bytes, filePath);
}
if (callback != null) {
callback.onPhotoTaken(bytes, filePath);
}
}
...
Here is the code changed:
...
@Override
public void onPhotoTaken(byte[] bytes, CameraFragmentResultListener callback) {
final String filePath = cameraController.getOutputFile().toString();
if (cameraFragmentResultListener != null) {
cameraFragmentResultListener.onPhotoTaken(bytes, filePath);
}
// if (callback != null) {
// callback.onPhotoTaken(bytes, filePath);
// }
}
...
in above code, cameraFragmentResultListener and callback is the same CameraFragmentResultListener . So you need to use one of them. Hope it can help someone.
On a Samsun S7, when setting the CameraFragmentResultListener in the cameraFragment causes it to onPhotoTaken to be called twice, setting the listener from takePhotoOrCaptureVideo (and removing it from cameraFragment) prevents/resolves this.