Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I would like to request you to add a description of the startMic and startRecording functions of RecordPlugin to the official document #3666

Open
milk717 opened this issue Apr 18, 2024 · 0 comments
Labels

Comments

@milk717
Copy link

milk717 commented Apr 18, 2024

Bug description

If RecordPlugin calls the startRecording function first and then the startMic function, the stream that was created by the startRecording call is overwritten by the startMic function call, making the first stream that was created indefinitely.
Therefore, it would be good if you could state in the official document that you need to call startMic before startRecording.
I didn't know these things, so I spent a lot of time trying to solve the issue of audio not shutting down.
If you try the code below, press the micro first button and press the stop audio button, the audio will end normally. However, if you shut down the audio after pressing the recording first button, the audio will not end.
I think adding these warnings to the document will reduce unnecessary time for many people due to this issue.

Environment

  • Browser: Arc

Minimal code snippet

import {useEffect, useRef} from "react";
import WaveSurfer from 'wavesurfer.js';
import RecordPlugin from 'wavesurfer.js/dist/plugins/record.js';

export default function Home() {
    const recorderRef = useRef<RecordPlugin | null>(null);
    useEffect(() => {
        const waveSurferInstance = WaveSurfer.create({
            container: '#waveform',
        });
        const recorderInstance = waveSurferInstance.registerPlugin(
            RecordPlugin.create({
                scrollingWaveform: true,
                renderRecordedAudio: false,
                mimeType: MediaRecorder.isTypeSupported('audio/webm')
                    ? 'audio/webm;codecs=pcm'
                    : 'audio/mp4',
            })
        );

        recorderRef.current = recorderInstance;
    }, []);

    const handleMicFirstButtonClick = async() => {
        await recorderRef.current?.startMic()
        recorderRef.current?.startRecording();
    }

    const handleRecordingFirstButtonClick = () => {
        recorderRef.current?.startRecording();
        recorderRef.current?.startMic()
    }

    const handleStopBoth = () => {
        recorderRef.current?.stopMic();
    }

    return (
        <main className="flex" id="waveform">
            <button className="p-4 border" onClick={handleMicFirstButtonClick}>mic first</button>
            <button className="p-4 border" onClick={handleRecordingFirstButtonClick}>recording first</button>
            <button className="p-4 border" onClick={handleStopBoth}>stop audio</button>
        </main>
    );
}

Expected result

Obtained result

Screenshots

2024-04-18.7.10.12.mov
@milk717 milk717 added the bug label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant