正在显示
1 个修改的文件
包含
38 行增加
和
0 行删除
| @@ -12,3 +12,41 @@ dependencies { | @@ -12,3 +12,41 @@ dependencies { | ||
| 12 | ``` | 12 | ``` |
| 13 | 13 | ||
| 14 | See our [release page](https://github.com/livekit/client-sdk-android/releases) for details on the current release version. | 14 | See our [release page](https://github.com/livekit/client-sdk-android/releases) for details on the current release version. |
| 15 | + | ||
| 16 | +## Usage | ||
| 17 | + | ||
| 18 | +### Register the CameraProvider | ||
| 19 | + | ||
| 20 | +``` | ||
| 21 | +CameraXHelper.createCameraProvider(lifecycleOwner).let { | ||
| 22 | + if (it.isSupported(application)) { | ||
| 23 | + CameraCapturerUtils.registerCameraProvider(it) | ||
| 24 | + | ||
| 25 | + // Save cameraProvider for unregistration later. | ||
| 26 | + cameraProvider = it | ||
| 27 | + } | ||
| 28 | +} | ||
| 29 | +``` | ||
| 30 | + | ||
| 31 | +Your activity can act as your `LifecycleOwner` for the camera provider. If you wish to use the camera beyond the lifecycle of a single activity, consider using | ||
| 32 | +[viewmodel-lifecycle](https://github.com/skydoves/viewmodel-lifecycle) for use within a view model (useful if your activity wants to handle rotation or other configuration changes), | ||
| 33 | +or `LifecycleService` from `androidx.lifecycle:lifecycle-service` to use in a service for backgrounded camera usage. | ||
| 34 | + | ||
| 35 | +Once registered, LiveKit will default to using CameraX when creating a camera video track. | ||
| 36 | + | ||
| 37 | +### Accessing the camera controls | ||
| 38 | + | ||
| 39 | +``` | ||
| 40 | +fun zoom(factor: Float) { | ||
| 41 | + val camera = localVideoTrack.capturer.getCameraX()?.value ?: return | ||
| 42 | + val zoomState = camera.cameraInfo.zoomState.value ?: return | ||
| 43 | + val currentZoom = zoomState.zoomRatio | ||
| 44 | + val newZoom = (currentZoom * factor).coerceIn(zoomState.minZoomRatio, zoomState.maxZoomRatio) | ||
| 45 | + | ||
| 46 | + if (newZoom != currentZoom) { | ||
| 47 | + camera.cameraControl.setZoomRatio(newZoom) | ||
| 48 | + } | ||
| 49 | +} | ||
| 50 | +``` | ||
| 51 | + | ||
| 52 | +We provide a convenience `ScaleZoomHelper` class that can handle pinch-to-zoom functionality as well. |
-
请 注册 或 登录 后发表评论