在所有浏览器中都可以正常工作,但是在IOS中我只能记录一次,接下来,直到重新加载页面,我才能记录一次。我不知道问题出在哪里,因为我没有收到任何错误。
componentDidMount = async () => {
let stream;
try {
stream = await navigator.mediaDevices.getUserMedia({ audio: true });
} catch (error) {
this.setState({
accept: false
})
}
this.setState({ stream });
}
startRecord = () => {
const { stream } = this.state;
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const recorder = new RecorderJS(audioContext);
recorder.init(stream);
this.setState(
{
recorder,
recording: true
},
() => {
recorder.start();
}
);
}
stopRecord = async () => {
const { recorder } = this.state;
recorder.stop().then(({ blob }) => {
this.uploadFile(blob);
})
this.setState({
recording: false
});
}