Code: Select all
import {
useCameraDevices,
Camera,
useCameraDevice,
useCameraPermission,
} from "react-native-vision-camera";
import { View, Button, Text } from "react-native";
import { useEffect, useState } from "react";
const DualCameraScreen = () => {
const device1 = useCameraDevice("front");
const device2 = useCameraDevice("back");
const { hasPermission, requestPermission } = useCameraPermission();
const [isRecording, setIsRecording] = useState(false);
if (!hasPermission) {
requestPermission();
}
const startRecording = async () => {
setIsRecording(true);
};
return (
{device1 && device2 && (
)}
);
};
export default DualCameraScreen;
< /code>
kehrte zu Android Studio (Kotlin) zurück, begann, dasselbe zu entwickeln und steckte wieder auf das gleiche Ding, diesmal seit ich im nativen Modus war, hatte ich Zugriff auf mehr Protokolle, die, welche zeigte mir, dass die maximal zulässigen Kameras des Telefons im Folgenden 1 ist. Der Code ist unten beigefügt: < /p>
Abhängigkeiten < /li>
< /ul>
implementation "androidx.camera:camera-core:1.4.1"
implementation "androidx.camera:camera-camera2:1.4.1"
implementation "androidx.camera:camera-lifecycle:1.4.1"
implementation "androidx.camera:camera-view:1.4.1"
< /code>
Kotlin -Datei < /li>
< /ul>
class DualCameraActivity : AppCompatActivity() {
private lateinit var backCameraPreview: PreviewView
private lateinit var frontCameraPreview: PreviewView
private var cameraProvider: ProcessCameraProvider? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dual_camera)
backCameraPreview = findViewById(R.id.backCameraPreview)
frontCameraPreview = findViewById(R.id.frontCameraPreview)
val cameraProviderFuture = ProcessCameraProvider.getInstance(this)
cameraProviderFuture.addListener({
cameraProvider = cameraProviderFuture.get()
bindDualCameras()
}, ContextCompat.getMainExecutor(this))
}
private fun bindDualCameras() {
val cameraProvider = cameraProvider ?: return
val cameraSelectorBack = CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_BACK)
.build()
val cameraSelectorFront = CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_FRONT)
.build()
val previewBack = Preview.Builder().build().also {
it.setSurfaceProvider(backCameraPreview.surfaceProvider)
}
val previewFront = Preview.Builder().build().also {
it.setSurfaceProvider(frontCameraPreview.surfaceProvider)
}
// Unbind any previously bound use cases
cameraProvider.unbindAll()
try {
// Bind both cameras
cameraProvider.bindToLifecycle(this, cameraSelectorBack, previewBack)
cameraProvider.bindToLifecycle(this, cameraSelectorFront, previewFront)
} catch (exc: Exception) {
Log.e("DualCameraActivity", "Use case binding failed", exc)
}
}
}
< /code>
XML -Datei < /li>
< /ul>
< /code>
Jetzt, nachdem ich ein bisschen mehr Nachforschungen anwesend habe, habe ich den folgenden Code erhalten: < /p>
val cameraManager = getSystemService(Context.CAMERA_SERVICE) as CameraManager
val cameraIdList = cameraManager.cameraIdList
for (id in cameraIdList) {
val characteristics = cameraManager.getCameraCharacteristics(id)
val capabilities = characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)
if (capabilities != null && capabilities.contains(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA)) {
Log.d("CameraInfo", "Device supports concurrent camera: $id")
}
}