logo
On this page

How to adjust the camera's focal length (zoom function)?

2022-07-07
Products / Plugins:Video Call / Live streaming
Platform / Framework:iOS / Android / uni-app

ZEGO provides camera zoom function. By setting the zoom factor of the camera through the SDK, you can achieve the effect of magnifying distant objects when shooting.

Usage Steps

Get the Maximum Zoom Factor of the Camera

Call the getCameraMaxZoomFactor interface to get the maximum zoom factor of the camera. The interface is only effective after the camera is successfully started. It is recommended to call it after receiving the onPublisherCapturedVideoFirstFrame callback.

  • iOS
- (void)onPublisherCapturedVideoFirstFrame:(ZegoPublishChannel)channel {
    self.maxZoomFactor = [[ZegoExpressEngine sharedEngine] getCameraMaxZoomFactor];
}
  • Android
ZegoExpressEngine.getEngine().setEventHandler(new IZegoEventHandler() {
    @Override
    public void onPublisherCapturedVideoFirstFrame(ZegoPublishChannel channel) {
    	float maxZoomFactor=ZegoExpressEngine.getEngine().getCameraMaxZoomFactor();
    }
});
  • uni-app
this.engine.on("publisherCapturedVideoFirstFrame", (channel) => {
    let maxZoomFactor = this.engine.getCameraMaxZoomFactor();
});

Set Camera Zoom Factor

Call the setCameraZoomFactor interface to set the zoom factor of the camera. The minimum value is "1.0", and the maximum value can be obtained from the getCameraMaxZoomFactor interface.

Note

When the camera is restarted, such as switching between front and rear cameras, disabling the camera and then restarting it, or setting mirroring, the zoom factor will be restored to the initial value.

  • iOS
[[ZegoExpressEngine sharedEngine] setCameraZoomFactor:self.maxZoomFactor];
  • Android
ZegoExpressEngine.getEngine().setCameraZoomFactor(maxZoomFactor);
  • uni-app
this.engine.setCameraZoomFactor(maxZoomFactor);

Previous

How to set Superboard logs?

Next

How to implement playing streams from CDN on the Web platform?

On this page

Back to top