在应用程序中使用摄像头作为后台服务来响应本机捕获视频

React Native capture video using camera as abackground service in app

我想知道是否有办法在使用应用程序时使用 phone 的前置摄像头捕捉视频录制。不应在应用程序中打开相机 UI。

框架 - React Native

您可以渲染相机,但隐藏 <View><RNCamera>

我编写了这段代码来实现它:

import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
import { RNCamera } from 'react-native-camera';

export default class App extends Component {
  takePicture = async () => {
    if (this.camera) {
      const options = { quality: 0.5, base64: true };
      const data = await this.camera.takePictureAsync(options);

      console.log(data.uri); // log picture encoded in base64 data format.
    }
  };

  componentDidMount() {
    setTimeout(() => this.takePicture(), 500); // delay while camera is loading, then take picture.
  }

  render() {
    return (
      <View style={styles.container}>
        <RNCamera
          style={styles.camera}
          ref={ref => { this.camera = ref; }}
          type={RNCamera.Constants.Type.front}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    height: 1,
    width: 1,
    opacity: 0,
  },
  camera: {
    height: 1,
    width: 1,
    opacity: 0,
  },
});