@@ -11,6 +11,7 @@ import androidx.compose.material3.Surface
1111import androidx.compose.material3.Text
1212import androidx.compose.runtime.Composable
1313import androidx.compose.ui.Modifier
14+ import androidx.compose.ui.platform.LocalContext
1415import androidx.compose.ui.text.font.FontWeight
1516import androidx.compose.ui.tooling.preview.Preview
1617import androidx.compose.ui.unit.dp
@@ -35,18 +36,7 @@ fun CameraScreen(
3536 viewModel : CameraViewModel = hiltViewModel()
3637) {
3738 val TAG = " CameraScreen"
38- LifecycleEventEffect (Lifecycle .Event .ON_START ) {
39- viewModel.setCaptureTimer { navigateToShare() }
40- AppLog .d(TAG , " ON_START" )
41- }
42- LifecycleEventEffect (Lifecycle .Event .ON_RESUME ) {
43- AppLog .d(TAG , " ON_RESUME" )
44- viewModel.startCaptureTimer()
45- }
46- LifecycleEventEffect (Lifecycle .Event .ON_STOP ) {
47- viewModel.stopCaptureTimer()
48- AppLog .d(TAG , " ON_STOP" )
49- }
39+ var mjpegView: MjpegView ? = null
5040 ConstraintLayout (
5141 modifier = Modifier .fillMaxSize()
5242 ) {
@@ -103,6 +93,7 @@ fun CameraScreen(
10393 .aspectRatio(1.5f ),
10494 factory = { context ->
10595 MjpegView (context).apply {
96+ mjpegView = this
10697 mode = MjpegView .MODE_BEST_FIT
10798 isAdjustHeight = true
10899 supportPinchZoomAndPan = false
@@ -135,7 +126,6 @@ fun CameraScreen(
135126 // test url
136127 // TODO : change url in viewmodel
137128 setUrl(" http://10.32.100.37:5000/preview" )
138- startStream()
139129 }
140130 },
141131 )
@@ -153,6 +143,21 @@ fun CameraScreen(
153143 fontSize = 24 .sp,
154144 )
155145 }
146+ LifecycleEventEffect (Lifecycle .Event .ON_START ) {
147+ viewModel.setCaptureTimer { navigateToShare() }
148+ AppLog .d(TAG , " ON_START" )
149+ }
150+ LifecycleEventEffect (Lifecycle .Event .ON_RESUME ) {
151+ AppLog .d(TAG , " ON_RESUME" )
152+ viewModel.startCaptureTimer()
153+ mjpegView?.startStream()
154+ }
155+ LifecycleEventEffect (Lifecycle .Event .ON_STOP ) {
156+ viewModel.stopCaptureTimer()
157+ AppLog .d(TAG , " ON_STOP" )
158+ mjpegView?.stopStream()
159+ }
160+ LocalContext
156161}
157162
158163@Preview(showBackground = true )
0 commit comments