问题
I'm running this wavesurfer microphone instance and i'm running into a problem called this.stop.stream
is not a function whenever i'm trying to stop the microphone after starting it.
This mic does not record anything - it's just visualizing. But in chrome the mic just stays open until reload. Which is not fun for users. And m.
I have found why that happens here => https://wavesurfer-js.org/api/file/src/plugin/microphone.js.html#lineNumber199
all the methods that are called after starting the mic are with "this".
I'm not advanced enough to find out how i could possibly stop that microphone.
Can someone help me please?
Thanks in advance
export default function InitialAudioRecording({ handleStop }) {
const [noAudioYet, setNoAudioYet] = React.useState(true);
const [isRecording, setIsRecording] = React.useState(false);
const [isProcessing, setIsProcessing] = React.useState(false);
const [waveSurfer, setWaveSurfer] = React.useState();
const [showWavesurfer, setShowWavesurfer] = React.useState(false);
const waveformRef = React.useRef();
React.useEffect(() => {
if (waveformRef.current) {
const themeGradient = getThemeGradient();
const wavesurfer = WaveSurfer.create({
container: waveformRef.current,
barWidth: 5,
barHeight: 10,
cursorWidth: 0,
waveColor: themeGradient,
hideScrollbar: true,
autoCenter: false,
responsive: true,
interact: false,
width: 100,
height: 350,
maxCanvasWidth: 2000,
fillParent: true,
plugins: [MicrophonePlugin.create()]
});
wavesurfer.microphone.on('deviceReady', function(stream) {
console.log('Device ready!', stream);
});
wavesurfer.microphone.on('deviceError', function(code) {
console.warn('Device error: ' + code);
});
setWaveSurfer(wavesurfer);
}
}, []);
const stopMicrophone = waveSurfer && waveSurfer.microphone.stopDevice.bind(waveSurfer);
function startRecording() {
waveSurfer.microphone.start();
setShowWavesurfer(true);
setNoAudioYet(false);
setIsRecording(true);
}
function handleData(recordedBlob) {
console.log('chunk of real-time data is: ', recordedBlob);
}
function stopRecording() {
waveSurfer.microphone.stop();
setIsRecording(false);
setIsProcessing(true);
setShowWavesurfer(false);
}
return (
<AudioInterfaceWrapper>
{noAudioYet && (
<>
<NoAudioYet systemMessage={'record a fiddle.'} />
</>
)}
{!noAudioYet && (
<>
<Mic record={isRecording} onStop={handleStop} onData={handleData} mimeType="audio/webm" />
{isProcessing && <LoadingLineLong />}
</>
)}
<Waveform showWavesurfer={showWavesurfer} ref={waveformRef} />
{isRecording && <StopButton onClick={stopRecording} />}
{!isRecording && !isProcessing && <RecordButton onClick={startRecording} />}
</AudioInterfaceWrapper>
);
}
来源:https://stackoverflow.com/questions/59734627/how-to-stop-wavesurfer-microphone-this-stop-stream-is-not-a-function