chris-rudmin / opus-recorder

A library for encoding and decoding web audio as OggOpus.
Other
957 stars 172 forks source link

Record dont work in Android 7.0 #108

Closed edubarbieri closed 6 years ago

edubarbieri commented 6 years ago

Hi, I am trying perform voice recording on Android 7.0 in Chrome 62.0 and i am getting the following error:

Uncaught DOMException: Failed to construct 'AudioContext': The number of hardware contexts provided (6) is greater than or equal to the maximum bound (6). at new n (http://../static/js/lib/recorder.min.js:1:982)

My recording code looks like this:


(function(Recorder) {

       function startRecording() {

        audioRecorder = new Recorder({
            monitorGain : 0,
            numberOfChannels : 1,
            wavBitDepth : 16,
            encoderPath : '/static/js/lib/waveWorker.min.js'
        });   

     }

       $('#btnVoiceSearch').click(function(){
            if(!recording){
                startRecording();
            }else{
                stopRecord();
            }
        });

})(Recorder);

Can you help me?

edubarbieri commented 6 years ago

I debug the code, the error happens because i create multiple instances of Recorder, but no event listener are called. Any idea ?

maxmatthews commented 6 years ago

Recorder should only be initialized once and then reused. Try something like this:

(function(Recorder) {
    audioRecorder = new Recorder({
        monitorGain : 0,
        numberOfChannels : 1,
        wavBitDepth : 16,
        encoderPath : '/static/js/lib/waveWorker.min.js',
        leaveStreamOpen: true
    });   

    function startRecording() {
        audioRecorder.start()
    }

    $('#btnVoiceSearch').click(function(){
        if(!recording){
            startRecording();
        }else{
            stopRecord();
        }
    });
})(Recorder);
edubarbieri commented 6 years ago

@maxmatthews Thanks for your answer.

I change my code and create only one instance of Recorder and the error did not happen anymore on android. About the event listener, i changed element in html and solve the problem.

The problem was my implantation not Record Js lib.