当我单击android设备上的“记录”按钮react-native-camera时,抛出错误“启动失败”。
Error: start failed.
at createErrorFromErrorData (NativeModules.js:155)
at NativeModules.js:104
at MessageQueue.__invokeCallback (MessageQueue.js:414)
at MessageQueue.js:127
at MessageQueue.__guard (MessageQueue.js:314)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:126)
at debuggerWorker.js:80
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
setCameraReady = () => {
this.setState({
cameraReady: true
});
};
startRecording = async () => {
const { cameraReady } = this.state;
if (cameraReady) {
try {
// default to mp4 for android as codec is not set
const { uri, codec = 'mp4' } = await this.camera.recordAsync({
maxDuration: 30
});
console.log(uri)
} catch (error) {
console.log(error);
}
}
};
stopRecording = () => {
this.camera.stopRecording();
};
<RNCamera
style={cameraStyle}
ref={(ref) => {
this.camera = ref;
}}
type={cameraType}
mirrorImage={cameraType !== 'back'}
androidCameraPermissionOptions={{
title: 'Permission to use camera',
message: 'We need your permission to use your camera phone',
buttonPositive: 'Ok',
buttonNegative: 'Cancel'
}}
androidRecordAudioPermissionOptions={{
title: 'Permission to use audio recording',
message: 'We need your permission to use your audio',
buttonPositive: 'Ok',
buttonNegative: 'Cancel'
}}
onCameraReady={this.setCameraReady}
/>
在recordAsync promise被解析后应该获取URI。
答案 0 :(得分:0)
感谢反应本地相机团队。
将react-native-camera更新到最新版本(即1.10.0)解决了该问题。