我可以用这个模块捕获图片,没有任何问题,但是当我尝试录制视频时,我似乎找不到录制的视频在哪里(或者甚至根本没有录制过视频)。这是我的CameraScreen
import Camera from 'react-native-camera';
const { CaptureMode, CaptureTarget } = Camera.constants;
const { video: captureModeVideo, still: captureModePhoto } = CaptureMode;
class CameraScreen extends Component {
constructor(props) {
super(props);
this.state = {
captureMode: captureModePhoto,
isRecording: false
};
this.onCapture = this.onCapture.bind(this);
this.onSwitchCaptureMode = this.onSwitchCameraMode.bind(this);
}
onCapture() {
const { captureMode, isRecording } = this.state;
if (isRecording) {
this._camera.stopCapture();
this.setState({ isRecording: false });
return;
}
if (captureMode === captureModeVideo) {
this.setState({ isRecording: true });
}
this._camera.capture({ mode: captureMode })
.then((result) => console.log(result))
.catch((error) => console.log(error));
}
onSwitchCaptureMode() {
if (this.state.captureMode === captureModeVideo) {
this.setState({ captureMode: captureModePhoto });
} else {
this.setState({ captureMode: captureModeVideo });
}
}
render() {
const { captureMode } = this.state;
return (
<Camera
ref={(ref) => this._camera = ref}
style={{ flex: 1 }}
captureMode={captureMode}
captureTarget={CaptureTarget.disk}
>
<TouchableOpacity onPress={this.onCapture}>
<Icon
name='camera-alt'
...
...
/>
</TouchableOpacity>
<TouchableOpacity onPress={this.onSwitchCaptureMode}>
<Icon
name='...'
...
...
/>
</TouchableOpacity>
</Camera>
);
}
}
export default CameraScreen;当我拍照时,console.log(result)语句记录照片的路径没有问题,但是当captureMode === captureModePhoto时,我的调试器中没有任何日志,是不是我做错了什么?我省略了许多样式以使代码更容易理解。
发布于 2018-04-25 07:11:27
这是一个愚蠢的错误
我发布的代码工作得非常好,但我必须在真实的设备上测试它。模拟器支持拍照(它会生成一些具有随机背景颜色的图片),但不支持拍照。因此,问题解决了
https://stackoverflow.com/questions/48637585
复制相似问题