React-Native-Audio-Toolkit 准备失败
React-Native-Audio-Toolkit failed to prepare
我正在尝试使用 React-native-audio-toolkit 构建我自己的 Recorder/Player。
按照他们的文档,但我不确定如何正确准备记录。
(在 iOS 模拟器上)
这是我的代码
const fileName = 'test.mp4';
let recorder = new Recorder(fileName, {
bitrate: 256000,
channels: 2,
sampleRate: 44100,
quality: 'high',
}).prepare((err, fspath) => {
if (err) {
console.log('recorder prepare failed: ', err);
} else if (!err) {
props.onFileURIChange(fspath);
console.log('fspath: ', fspath);
recorder.record();
}
});
错误是
recorder prepare failed: {
"err": "preparefail", "message": "Failed to prepare recorder. Settings are probably wrong.",
"stackTrace": [
"0 myapp 0x000000010a2f61cf +[Helpers errObjWithCode:withMessage:] + 159",
"1 myapp 0x000000010a2f4cb3 -[AudioRecorder prepare:withPath:withOptions:withCallback:] + 2707",
"2 CoreFoundation 0x00007fff23e43e8c __invoking___ + 140",
"3 CoreFoundation 0x00007fff23e41071 -[NSInvocation invoke] + 321",
"4 CoreFoundation 0x00007fff23e41344 -[NSInvocation invokeWithTarget:] + 68",
"5 myapp 0x000000010a06edc4 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2660",
"6 myapp 0x000000010a072f91 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 801",
"7 myapp 0x000000010a072a66 _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 134",
"8 myapp 0x000000010a0729cc ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 28",
"9 libdispatch.dylib 0x00007fff519e2951 _dispatch_call_block_and_release + 12",
"10 libdispatch.dylib 0x00007fff519e38cb _dispatch_client_callout + 8",
"11 libdispatch.dylib 0x00007fff519e960c _dispatch_lane_serial_drain + 707",
"12 libdispatch.dylib 0x00007fff519ea044 _dispatch_lane_invoke + 388",
"13 libdispatch.dylib 0x00007fff519f40c4 _dispatch_workloop_worker_thread + 626",
"14 libsystem_pthread.dylib 0x00007fff51c096fc _pthread_wqthread + 290",
"15 libsystem_pthread.dylib 0x00007fff51c08827 start_wqthread + 15"
]
}
注意:我尝试使用默认的 recorderOptions 但同样的错误:(
注意:这只发生在模拟器上。在真实设备上,它运行良好。 :)
你更新你的 info.plist 了吗?
如果没有,您可能需要添加以下行:
<key>NSMicrophoneUsageDescription</key>
<string>The description why you need to use microphone.</string>
或添加隐私-麦克风使用说明
我正在尝试使用 React-native-audio-toolkit 构建我自己的 Recorder/Player。
按照他们的文档,但我不确定如何正确准备记录。
(在 iOS 模拟器上)
这是我的代码
const fileName = 'test.mp4';
let recorder = new Recorder(fileName, {
bitrate: 256000,
channels: 2,
sampleRate: 44100,
quality: 'high',
}).prepare((err, fspath) => {
if (err) {
console.log('recorder prepare failed: ', err);
} else if (!err) {
props.onFileURIChange(fspath);
console.log('fspath: ', fspath);
recorder.record();
}
});
错误是
recorder prepare failed: {
"err": "preparefail", "message": "Failed to prepare recorder. Settings are probably wrong.",
"stackTrace": [
"0 myapp 0x000000010a2f61cf +[Helpers errObjWithCode:withMessage:] + 159",
"1 myapp 0x000000010a2f4cb3 -[AudioRecorder prepare:withPath:withOptions:withCallback:] + 2707",
"2 CoreFoundation 0x00007fff23e43e8c __invoking___ + 140",
"3 CoreFoundation 0x00007fff23e41071 -[NSInvocation invoke] + 321",
"4 CoreFoundation 0x00007fff23e41344 -[NSInvocation invokeWithTarget:] + 68",
"5 myapp 0x000000010a06edc4 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2660",
"6 myapp 0x000000010a072f91 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 801",
"7 myapp 0x000000010a072a66 _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 134",
"8 myapp 0x000000010a0729cc ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 28",
"9 libdispatch.dylib 0x00007fff519e2951 _dispatch_call_block_and_release + 12",
"10 libdispatch.dylib 0x00007fff519e38cb _dispatch_client_callout + 8",
"11 libdispatch.dylib 0x00007fff519e960c _dispatch_lane_serial_drain + 707",
"12 libdispatch.dylib 0x00007fff519ea044 _dispatch_lane_invoke + 388",
"13 libdispatch.dylib 0x00007fff519f40c4 _dispatch_workloop_worker_thread + 626",
"14 libsystem_pthread.dylib 0x00007fff51c096fc _pthread_wqthread + 290",
"15 libsystem_pthread.dylib 0x00007fff51c08827 start_wqthread + 15"
]
}
注意:我尝试使用默认的 recorderOptions 但同样的错误:(
注意:这只发生在模拟器上。在真实设备上,它运行良好。 :)
你更新你的 info.plist 了吗?
如果没有,您可能需要添加以下行:
<key>NSMicrophoneUsageDescription</key>
<string>The description why you need to use microphone.</string>
或添加隐私-麦克风使用说明