问题描述
expo-av出现了奇怪的问题。我有录音屏幕,当我第一次打开屏幕时,它可以正常工作。当我返回并重新打开屏幕并尝试录制声音时,出现“开始遇到错误:录制未开始”错误。这是代码:
@action async startRecording() {
try {
// If stills recording,do not start a new one
if (this.props.store.chatStore.isDeviceRecording)
return;
await this._setAudioMode({
allowsRecordingIOS: true
});
// Creating Audio Recording object
const recording = new Audio.Recording();
await recording.preparetoRecordAsync(Audio.RECORDING_OPTIONS_PRESET_HIGH_QUALITY);
recording.setonRecordingStatusUpdate(this._recordingCallback);
this.setRecording(recording);
// Link Audio Recording object with storage
await this.recording.startAsync().then((v) => {
this.props.store.chatStore.setIsDeviceRecordingStarted(true);
});
} catch (error) {
console.log(error);
}
}
@action async cancelRecording() {
try {
if (this.recording) {
await this.recording.stopAndUnloadAsync();
this.recording.setonRecordingStatusUpdate(null);
this.recording = null;
}
await this._setAudioMode({
allowsRecordingIOS: false
});
this.props.store.chatStore.setValues({
isDeviceRecordingStarted: false,isRecordingCancelled: false
});
} catch (e) {
console.log(e);
}
}
@action async stopRecording() {
try {
if (!this.recording)
return;
await this.recording.stopAndUnloadAsync();
await this._setAudioMode({
allowsRecordingIOS: false
});
if (!this.props.store.chatStore.isDeviceRecording) {
const fileUrl = this.recording.getURI();
this.recording.setonRecordingStatusUpdate(null);
const status = await this.recording.getStatusAsync();
this.recording = null;
// Save audio message
const uid = this.props.store.userStore.uid,chatMessage = new ChatMessage({
id: MiscHelper.getUUID(),type: CHAT_MESSAGE_TYPE.AUdio,status: CHAT_MESSAGE_STATUS.SENDING,creation_time: new Date(),audio: {
source: fileUrl,duration: status.durationMillis
},sender: {
id: uid,user_type: CHAT_SENDER_USER_TYPE.USER
}
});
this.props.store.chatStore.saveMessage(chatMessage);
this.props.store.chatStore.setIsDeviceRecordingStarted(false);
}
} catch (error) {
console.log(error);
}
}
async _setAudioMode({allowsRecordingIOS}) {
try {
await Audio.setAudioModeAsync({
allowsRecordingIOS,interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,playsInSilentModeIOS: true,shouldDuckAndroid: true,interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,playThroughEarpieceAndroid: false,staysActiveInBackground: true
});
} catch (e) {
console.log(e);
}
}
任何帮助将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)