本文介绍了我如何访问react-native-camera的视频功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使react-native-camera的视频功能正常工作,但是尝试了很多方法,但始终遇到相同的错误.这是我的代码:

I've been attempting to get the react-native-camera's video feature to work, but and have tried a vast number of methods but keep getting the same errors. Here is my code:

class MainCamera extends Component {
  constructor() {
  super();
  this.render = this.render.bind(this)
  this.state = { cameraType: Camera.constants.Type.back }
}

  render() {

return (
  <View style={styles.container}>
    <Camera
      ref='camera'
      style={styles.preview}
      aspect={Camera.constants.Aspect.fill}
      type={this.state.cameraType}
      captureMode={Camera.constants.CaptureMode.video}
      captureAudio={false}
      target={Camera.constants.CaptureTarget.disk}>

      <TouchableHighlight
        onPressIn={this.onPressIn.bind(this)}
        onPressOut={this.stopVideo.bind(this)}>
        <Icon name="video-camera" size={40} />
      </TouchableHighlight>
    </Camera>
  </View>
);
  }

onPressIn() {
  recordVideo = setTimeout(this.takeVideo.bind(this), 100);
}

takeVideo() {
    this.refs.camera.capture({
      target: Camera.constants.CaptureTarget.disk
    })
      .then(data => {
        console.log(data);
      })
      .catch(err => console.log(err));
  }

stopVideo() {
  this.refs.camera.stopCapture({})
    .then(data => console.log(data))
    .catch(err => console.log(err));
  }
}

当我在stopCapture()方法上使用'.then'承诺时,收到错误消息无法读取未定义的'then'属性",但是如果我不添加'.then',则什么也不会发生而且我没有收到任何数据有人有什么建议吗?

When I use the '.then' promise on the stopCapture() method, I receive the error "Cannot read property 'then' of undefined", but if I don't add the '.then', then nothing happens and I don't receive any data. Does anybody have any suggestions?

推荐答案

takeVideo() {
    this.refs.camera.capture({
      audio: true,
      mode: Camera.constants.CaptureMode.video,
      target: Camera.constants.CaptureTarget.disk
    })
      .then((data) => {
        console.log(data);
      })
      .catch((err) => console.log(err));
  }

stopVideo() {
  this.refs.camera.stopCapture();
}

stopCapture()功能不是一个承诺.

这篇关于我如何访问react-native-camera的视频功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 16:21