Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
一个按钮用于更多功能=在JavaScript中录制_Javascript_Html - Fatal编程技术网

一个按钮用于更多功能=在JavaScript中录制

一个按钮用于更多功能=在JavaScript中录制,javascript,html,Javascript,Html,我有这个源代码在浏览器中录制音频。Record.js调用另一个脚本,该脚本提供录制音频并将其保存到服务器 index.html 好吧,你是在无中生有地调用一个方法 getAttribute('data-run')应该类似于this.getAttribute('data-run')或按钮.getAttribute('data-run')取决于上下文。您可能正在寻找类似的内容 var audioContext; var recorder; var recording = false; var in

我有这个源代码在浏览器中录制音频。Record.js调用另一个脚本,该脚本提供录制音频并将其保存到服务器

index.html


好吧,你是在无中生有地调用一个方法


getAttribute('data-run')
应该类似于
this.getAttribute('data-run')
按钮.getAttribute('data-run')取决于上下文。

您可能正在寻找类似的内容

var audioContext;
var recorder;
var recording = false;
var initialized = false;

var recordButton = document.getElementById('recordBtn');
recordButton.addEventListener('click', start);

//function which is called by click on button
function start(e) {
    e.preventDefault();
    if (!initialized) {
        init();
    }
    toggleRecording(e.target);
}

function init() {
    try {
        window.AudioContext = window.AudioContext || window.webkitAudioContext;
        navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia;
        window.URL = window.URL || window.webkitURL;
        audioContext = new AudioContext();
    } catch (e) {
        alert('This browser do not support audio!');
    }
    navigator.getUserMedia({
        audio: true
    }, startUserMedia, function (e) {
        __log('No audio was detected: ' + e);
    });
    initialized = true;
};



function startUserMedia(stream) {
    var input = audioContext.createMediaStreamSource(stream);
    recorder = new Recorder(input);
    __log('System for recording is available.');
};

//starts by click on button
function toggleRecording(button) {
    if (recording) {
        recorder && recorder.stop();
        recorder && recorder.exportWAV(function (blob) {
            alert(blob.size);
        });
        __log('Recording is stopped');
        recording = false;
        button.innerText = "Start";
    } else {
        recorder && recorder.clear();
        recorder && recorder.record();
        __log('Speak...');
        recording = true;
        button.innerText = "Stop";
    }
};

function __log(e, data) {
    console.log("\n" + e + " " + (data || ''));
};

var run=parseInt(getAttribute('data-run');您尝试运行属性数据,但不执行任何操作。。。。这就是问题所在。。。您必须从按钮获取属性,就像下面在代码中所做的那样…var run=parseInt(button.getAttribute('data-run'))@Julo0sS问题已更新。我用“button”元素尝试了它,但它的工作方式相同,并且显示了相同的错误消息。我将它修改为:function-toggleRecording(button),{var-run=parseInt(button.getAttribute('data-run'));button.setAttribute('data-run',0);}但显示了相同的错误:(不,它的工作方式与没有“button”时的工作方式相同),所以它不能正常工作。您在哪里初始化按钮变量?它是否正确初始化?如果您执行console.log(按钮),它会显示什么?顺便说一句,您应该接受前面问题的答案,如果他们确实回答了您的问题。