我一直在尝试让 react-native-camera 的视频功能正常工作,但是我尝试了很多方法,但总是遇到同样的错误。这是我的代码:
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',则什么也不会发生,我不会'没有收到任何数据。有人有什么建议吗?