反应原生相机视频功能如何录制视频

时间:2017-12-01 02:08:08

标签: android react-native

如何激活/使用https://github.com/lwansbrough/react-native-camera

中的视频功能

目前,我可以拍照,但我想录制视频。当我点击开始录制文本按钮时,应用程序只是崩溃,我不知道如何获取错误日志。

以下是我为尝试录制视频而编写的代码

   import React, { Component } from 'react';
    import {
      Platform,
      StyleSheet,
      Text,
      View,
      AppRegistry,
      TouchableHighlight,
    } from 'react-native';

    import {StackNavigator} from 'react-navigation'
    import Camera from 'react-native-camera'

    export default class CameraScreen extends React.Component {
        static navigationOptions = {
            tabBarLabel: 'Camera'
        };

      render() {
        return (
      <View style={styles.container}>

         <Camera 

          ref={(cam) => {
            this.camera = cam;
          }}
          style={styles.preview}
          aspect={Camera.constants.Aspect.fill}
          //type = {Camera.constants.Type.front}
          captureMode = {Camera.constants.CaptureMode.video}

          keepAwake={true}
          >


          <Text style={styles.capture} onPress={this.takeVid.bind(this)}> Start recording </Text>
          <Text style={styles.capture} onPress={this.stopVid.bind(this)}> Stop recording </Text>
        </Camera>
      </View>
    );
  }

  takeVid() {
    const option = {};
    //options.location = ...
    this.camera.capture({
      mode: Camera.constants.CaptureMode.video
    })
      .then((data) => console.log(data))
      .catch((err) => console.error(err));
  }

  stopVid(){
   //console.log("I am pressed");
    this.camera.stopCapture();
  }
}

0 个答案:

没有答案