Skip to content

Instantly share code, notes, and snippets.

@mayowa-egbewunmi
Last active July 31, 2022 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayowa-egbewunmi/3e8270cde5d2c0b52d8136f2e22a7d8b to your computer and use it in GitHub Desktop.
Save mayowa-egbewunmi/3e8270cde5d2c0b52d8136f2e22a7d8b to your computer and use it in GitHub Desktop.
@Composable
internal fun RecordingScreen(viewModel: RecordingViewModel) {
val state by viewModel.state.collectAsState()
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current
val listener = remember {
object : VideoCaptureManager.Listener {
override fun onInitialised(cameraLensInfo: HashMap<Int, CameraInfo>) {
//TODO: Dispatch an Event to the viewModel to update State with CameraInfo
}
}
}
val captureManager = remember {
VideoCaptureManager.Builder(context)
.registerLifecycleOwner(lifecycleOwner)
.create()
.apply { this.listener = listener }
}
CompositionLocalProvider(LocalVideoCaptureManager provides captureManager) {
CameraPreview(lens = state.lens, torchState = state.torchState)
}
}
@Composable
private fun CameraPreview(lens: Int, @TorchState.State torchState: Int) {
val captureManager = LocalVideoCaptureManager.current
BoxWithConstraints {
AndroidView(
factory = {
captureManager.showPreview(
PreviewState(
cameraLens = lens,
torchState = torchState,
size = Size(this.minWidth.value.toInt(), this.maxHeight.value.toInt())
)
)
},
modifier = Modifier.fillMaxSize(),
update = {
captureManager.updatePreview(PreviewState(cameraLens = lens, torchState = torchState), it)
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment