问题描述:

I am currently developing an app using the Twilio Video API: https://www.twilio.com/video

It is still in Beta, but works great for the most part. And maybe there is also a way to solve my issue.

For my app I need to switch the camera and to turn on the light of the back camera. The first one is easily done with Twilio, but for the second one I do not have the camera object to control the camera light. Is there any way to get the camera object? Or can I create the camera object myself and then pass it to Twilio? Or is there another approach to turn on the light?

My code for the camera preview. As in the examples I use the CameraCapturer to get the camera preview into a view:

cameraCapturer = CameraCapturer.create(MyActivity.this, CameraCapturer.CameraSource.CAMERA_SOURCE_FRONT_CAMERA, capturerErrorListener());

startPreview();

and the preview:

private void startPreview() {

if (cameraCapturer != null) {

cameraCapturer.startPreview(previewFrameLayout);

}

}

网友答案:

Twilio Developer Evangelist here. You are right, and the current version of the SDK does not allow for you to control the Camera Capturer as you could if you just created the camera object yourself.

We are aware of this though, and are working on a new version where you will be able to do just that.

For the time being I would suggest trying to still create your own camera object manually just so you can turn on the backlight, and I think that as long as you don't call preview on it, you shouldn't end up with a conflict.

I would imagine something like this (untested) would work.

private void turnOnFlash() {
    Camera camera = Camera.open();
    Camera.Parameters params = camera.getParameters();
    params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
    camera.setParameters(params);
}

Also add this to your AndroidManifest.

<permission android:name="android.permission.FLASHLIGHT"
        android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
        android:protectionLevel="normal" />

And then you would call that method where you call startPreview().

This solutions should get you going for the time being, but you will be able to pass your own camera object in the future, so if that's not a pressing functionality for the time being, I would then wait for the updated version.

Hope this helps you

相关阅读:
Top