问题
我一直在尝试弄清楚为什么这不起作用已经有一段时间了。我使用了很多示例代码,但是我仍然无法弄清楚。
代码
takeVideo() {
console.log('started to take video');
this.camera.capture({
audio: true,
mode: Camera.constants.CaptureMode.video,
target: Camera.constants.CaptureTarget.disk
}).then((data) => {
this.setState({ path: data.path });
console.log(data);
}).catch((err) => console.log(err));
}
stopVideo() {
this.camera.stopCapture();
console.log(this.state.path);
}
renderCamera() {
return (
<View>
<Camera
ref={(cam) => {
this.camera = cam;
}}
style={styles.preview}
aspect={Camera.constants.Aspect.fill}
captureTarget={Camera.constants.CaptureTarget.disk}
captureMode={Camera.constants.CaptureMode.video}
>
<TouchableHighlight
style={styles.capture}
onPressIn={this.takeVideo.bind(this)}
onPressOut={this.stopVideo.bind(this)}
underlayColor="rgba(255, 255, 255, 0.5)"
>
<View />
</TouchableHighlight>
</Camera>
</View>
);
}
问题描述
当我使用console.log(this.state.path)
时,输出的结果是false
,这意味着它没有改变,视频没有录制成功。
信息
- 这是在IOS系统上进行的
- 如果我将
Camera.constants.CaptureMode.video
更改为Camera.constants.CaptureMode.still
(.video
=>.still
),则这个问题就被解决了 - RN版本:
react-native-cli: 2.0.1
react-native: 0.44.0
代码库
我找到了一个与我几乎完全相同的代码库,也遇到了同样的问题。这是代码库链接:https://github.com/MiLeung/record
captureTarget= {Camera.constants.CaptureTarget.cameraRoll}
,在 render 中定义相机。 - eden