1

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 ?

KYHSGeekCode
  • 1,068
  • 2
  • 12
  • 30

1 Answers1

0

Try using reflection to get the camera object.

Modified this

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
  • @SayedShalan Did it help? – KYHSGeekCode Apr 03 '18 at 22:26
  • 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