最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Using both cameras (front and back) at once with React native expo (library: react-native-vision-camera) - Stack Overflow

programmeradmin0浏览0评论

Only one camera works at a time with following code. I have read some old articles saying this is not possible so I want to ask if it's still not possible because my phone's camera application can do this so I know there's some way.

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 (
    <View style={{ flex: 1 }}>
      {device1 && device2 && (
        <View
          style={{ flex: 1, flexDirection: "column", backgroundColor: "green" }}
        >
          <Camera
            style={{ flex: 1 / 3, width: "100%" }}
            device={device1}
            isActive={true}
            video={true}
          />
          <Camera
            style={{ flex: 1 / 3, width: "100%" }}
            device={device2}
            isActive={true}
          />
        </View>
      )}
    </View>
  );
};

export default DualCameraScreen;

Only one camera works at a time with following code. I have read some old articles saying this is not possible so I want to ask if it's still not possible because my phone's camera application can do this so I know there's some way.

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 (
    <View style={{ flex: 1 }}>
      {device1 && device2 && (
        <View
          style={{ flex: 1, flexDirection: "column", backgroundColor: "green" }}
        >
          <Camera
            style={{ flex: 1 / 3, width: "100%" }}
            device={device1}
            isActive={true}
            video={true}
          />
          <Camera
            style={{ flex: 1 / 3, width: "100%" }}
            device={device2}
            isActive={true}
          />
        </View>
      )}
    </View>
  );
};

export default DualCameraScreen;
Share Improve this question asked Feb 2 at 12:26 Jazzel MehmoodJazzel Mehmood 51 silver badge4 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Camera 2 is missing its

video={true}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论