Last active
July 31, 2022 18:45
-
-
Save mayowa-egbewunmi/3e8270cde5d2c0b52d8136f2e22a7d8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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