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));
}
}
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?