I am developing a camera application with Face Detection using Camera Source
, but I can't record video using CameraSource
with MediaRecorder.setCamera();
that requires hardware Camera. Any help to record using CameraSource
?
Asked
Active
Viewed 565 times
1

KYHSGeekCode
- 1,068
- 2
- 12
- 30

Sayed Shalan
- 83
- 4
-
Could you post some codes that use the CameraSource and MediaRecorder? To make better answer. – KYHSGeekCode Apr 08 '18 at 15:13
1 Answers
0
Try using reflection to get the camera object.
private static Camera getCamera(@NonNull CameraSource cameraSource) {
Field[] declaredFields = CameraSource.class.getDeclaredFields();
for (Field field : declaredFields)
{
if (field.getType() == Camera.class)
{
field.setAccessible(true);
try {
Camera camera = (Camera) field.get(cameraSource);
if (camera != null)
{
return camera;
}
return null;
} catch (IllegalAccessException e) {
e.printStackTrace();
}
break;
}
}
return null;
}

KYHSGeekCode
- 1,068
- 2
- 12
- 30
-
_I want to cast_ **CameraSource** _that exists in mobile Vision to_ **Camera** _hardware_ – Sayed Shalan Mar 28 '18 at 16:51
-
-
unfortunately no , **MediaRecorder** opened it own camera at the time **CameraSource** is opened so conflict is occurred , i actually have the **cameraSourcePreview** and i applied some of **image processing** such **faceDetection** , i want any way to record video using this camera , or record this camera as a view!! – Sayed Shalan Apr 04 '18 at 08:50
-
@SayedShalan then does the first code work? Or both codes aren't working? – KYHSGeekCode Apr 04 '18 at 10:16
-
first code works perfectly , but the mediaRecorder open new Camera!!, I want MediaRecorder not opens any Camera and use My actually opened CameraSource – Sayed Shalan Apr 04 '18 at 13:26