首页 > 解决方案 > 带“录音机”的鼓机

问题描述

我在 freecodecamp 上的鼓机项目完成了一半,刚刚遇到了这里有人制作的具有录音和播放功能的完成作品。但是,此功能仅播放以不变的速度捕获的音符。如果我以各种节奏单击键盘,则不会捕获此模式。例如,如果我在两秒内点击“Q”键盘 10 次,然后在录制模式下以每秒 1 次点击的速度点击“W”键盘两次,则不会记录此点击与时间模式。有谁知道如何实现这一目标?

playSound(e) {
    //console.log('In playSound power = ' + this.props.power);
    if (this.props.power) {
        const sound = document.getElementById(this.props.keyTrigger);
        sound.currentTime = 0;
        sound.play();

        const button = document.getElementById(this.props.id);
        button.style.backgroundColor = "#00c7ec";
        setTimeout(() => { button.style.backgroundColor = '#012839'; }, 500);
        this.props.updateDisplay(this.props.id, 500);

        if (this.props.){
            // record key in array
            recordArray.push(this.props.keyCode);
        }
    }
}

标签: javascriptreactjs

解决方案


推荐阅读