如何解决expo-av-当我向后浏览并重新打开屏幕时,出现“开始遇到错误:录制未开始”错误
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 举报,一经查实,本站将立刻删除。