Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.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 如何暂停当前正在使用getusermedia录制的录制?_Javascript_Html_Asp.net - Fatal编程技术网

Javascript 如何暂停当前正在使用getusermedia录制的录制?

Javascript 如何暂停当前正在使用getusermedia录制的录制?,javascript,html,asp.net,Javascript,Html,Asp.net,我正在使用getusermedia和webaudioAPI录制来自用户的音频。我能够录制并将录制的数据保存到服务器,然后我尝试暂停/恢复录制。下面的代码是我尝试的代码,但显示以下错误 1>InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable at function resumeRecording() var记录按钮、停止按钮、记录器; window.onlo

我正在使用getusermedia和webaudioAPI录制来自用户的音频。我能够录制并将录制的数据保存到服务器,然后我尝试暂停/恢复录制。下面的代码是我尝试的代码,但显示以下错误

1>InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable at function resumeRecording()
var记录按钮、停止按钮、记录器;
window.onload=函数(){
navigator.mediaDevices.getUserMedia({
音频:正确
})
.then(函数(流){
如果(记录器==null){
记录器=新的媒体记录器(流);
recorder.addEventListener('dataavailable',onRecordingReady);
}
}).catch(函数(err){
警报(错误)
});;
};
函数startRecording(){
//recordButton.disabled=true;
//stopButton.disabled=false;
recorder.start();
}
函数stopRecording(){
//recordButton.disabled=false;
//stopButton.disabled=true;
录音机。停止();
}
函数暂停录制()
{
if(记录器记录){
录音机。停止();
}
}
函数resumecording()
{
recorder.start();
}
按钮点击:

   $(document).on('click','.btnPause',function(){

            x(this.title);
            $(this).html('Resume');
            $(this).removeClass('btnPause');
            $(this).addClass('btnResume');
            pauseRecording();
            return false;

        });
        $(document).on('click','.btnResume',function(){
            x(this.title);
            $(this).html('Resume');
            $(this).removeClass('btnResume');
            $(this).addClass('btnPause');
            resumeRecording();      
            return false;
        });

我怎样才能做到这一点?需要您的帮助,如果有人能帮我度过难关,我将不胜感激。

以下是我如何克服这种情况暂停和恢复以前不适用于mediarecorderAPI,但现在可以使用MediaRecorder.pause()MediaRecorder.resume()函数来暂停和恢复


以下是我如何克服mediarecorderAPI以前无法使用暂停和恢复功能的情况,但现在可以使用MediaRecorder.pause()MediaRecorder.resume()功能进行暂停和恢复

 $(document).on('click','.btnPause',function(){


       x(this.title);
        if (recorder.state === "recording") {

            recorder.pause();
            $(this).html('Resume');
          //  Console.log(recorder.state);
            // recording paused
        } else if (recorder.state === "paused") {
            $(this).html('Pause');
            recorder.resume();
            // resume recording
        }
        return false;

    });