Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

reactjs - Wavesurfer microphone is not displaying correctly in React

Im trying to use WaveSurfer microphone plugin in my React app but I've got problem that waves are showing randomly. From time to time they are not generated correctly, they are invisible but wave html is generated succesfully. Thats really werid because its seems like I do everything as its documented. I tried to replace #wave form container with ref but it doesnt help.

import React from 'react'
import WaveSurfer from 'wavesurfer.js';
import MicrophonePlugin from 'wavesurfer.js/dist/plugin/wavesurfer.microphone';
import { withTheme } from 'styled-components';

const Recording = ({ theme }) => {
React.useEffect(() => {
    const waveSurfer = WaveSurfer.create({
        container: '#waveform',
        height: 200,
        waveColor: theme.palette.primary.main,
        interact: false,
        cursorWidth: 0,
        plugins: [
            MicrophonePlugin.create({
                container: '#waveform',
            }),
        ],
    });

    waveSurfer.microphone.on('deviceReady', function() {
        console.info('Device ready!');
    });

    waveSurfer.microphone.start();

    return () => {
        waveSurfer.microphone.stop();
        waveSurfer.destroy();
    };

}, [WaveSurfer, MicrophonePlugin]);

return (
    <>
        <div style={{ position: 'relative' }}>
            <div id="waveform" />
        </div>
    </>
);

};

export default withTheme(Recording);

question from:https://stackoverflow.com/questions/65935794/wavesurfer-microphone-is-not-displaying-correctly-in-react

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...