@@ -16,6 +16,7 @@ import androidx.compose.ui.platform.LocalLifecycleOwner
1616import  androidx.compose.ui.viewinterop.AndroidView 
1717import  androidx.core.content.ContextCompat 
1818import  androidx.lifecycle.LifecycleOwner 
19+ import  kotlin.time.Duration.Companion.seconds 
1920
2021@Composable
2122fun  CameraView (
@@ -67,18 +68,19 @@ private fun bindPreview(
6768            .also  {
6869                it.setAnalyzer(
6970                    ContextCompat .getMainExecutor(previewView.context),
70-                     SecondIntervalAnalyzer (onFrameCaptured),
71+                     SnapshotFrameAnalyzer (onFrameCaptured),
7172                )
7273            }
7374
7475    cameraProvider.unbindAll()
7576    cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector, preview, imageAnalysis)
7677}
7778
78- private  class  SecondIntervalAnalyzer (private  val  onFrameCaptured :  (Bitmap ) ->  Unit ) :
79+ //  Calls the [onFrameCaptured] callback with the captured frame every second.
80+ private  class  SnapshotFrameAnalyzer (private  val  onFrameCaptured :  (Bitmap ) ->  Unit ) :
7981    ImageAnalysis .Analyzer  {
8082    private  var  lastFrameTimestamp =  0L 
81-     private  val  interval =  1000L  //  1 second
83+     private  val  interval =  1 .seconds  //  1 second
8284
8385    @SuppressLint(" UnsafeOptInUsageError"  )
8486    override  fun  analyze (image :  ImageProxy ) {
@@ -87,7 +89,7 @@ private class SecondIntervalAnalyzer(private val onFrameCaptured: (Bitmap) -> Un
8789            lastFrameTimestamp =  currentTimestamp
8890        }
8991
90-         if  (currentTimestamp -  lastFrameTimestamp >=  interval) {
92+         if  (currentTimestamp -  lastFrameTimestamp >=  interval.inWholeMilliseconds ) {
9193            onFrameCaptured(image.toBitmap())
9294            lastFrameTimestamp =  currentTimestamp
9395        }
0 commit comments