Skip to content

Commit 1fae483

Browse files
committed
Better naming
1 parent af5b172 commit 1fae483

File tree

1 file changed

+6
-4
lines changed
  • firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/live

1 file changed

+6
-4
lines changed

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/live/CameraView.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import androidx.compose.ui.platform.LocalLifecycleOwner
1616
import androidx.compose.ui.viewinterop.AndroidView
1717
import androidx.core.content.ContextCompat
1818
import androidx.lifecycle.LifecycleOwner
19+
import kotlin.time.Duration.Companion.seconds
1920

2021
@Composable
2122
fun 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

Comments
 (0)