How Can I Set The Share Audio Checkbox To Always True On The Choose What To Share Popup Window?

768 Views Asked by At

I have reused / modified the available demo samples from RecordRTC as part of my project requirements. Now, I can record Camera + Mic with Screen Recording + Microphone / Speaker Audio.

Because, I have included audio: true in getDisplayMedia(), it show the Share Audio checkbox in the Choose What To Share popup window which actually allows the user to record the speaker / microphone audio with screen sharing. Here is the code sample for including the Share Audio checkbox on the popup window:

if (navigator.mediaDevices.getDisplayMedia) {
        navigator.mediaDevices.getDisplayMedia({video: true, audio: true}).then(success).catch(error);
}
else {
     navigator.getDisplayMedia({video: true, audio: true}).then(success).catch(error);
}

Currently, the Share Audio checkbox appears as unchecked by default like as follow:

enter image description here

I want this to be always set to true / checked. I've observed that the same checkbox is always set to true / checked by default within the google chrome extension when a user choose to record screen with speaker / microphone sound. I have already done the same functionality in my project as well except the checkbox appears unchecked by default. I want it to be checked by default.

Is it possible with custom JavaScript or JQuery code or do I have to modify system / chrome setting?

1

There are 1 best solutions below

0
On

you can get audio stream first then add it to display video stream

navigator.mediaDevices.getUserMedia({
                        audio:true
                    }).then(function(audioStream){
                        console.log(audioStream);
                        navigator.mediaDevices.getDisplayMedia({
                            video: {
                            cursor: "always",
                            frameRate: {
                              ideal: 5,
                              max: 10
                            }
                          },
                          audio: false,
                        }).then(function(stream){
                            window.localStream=stream;
                            window.localStream.addTrack(audioStream.getAudioTracks()[0]);
                            //use your stream
                        }).catch(function(error){
                            alert(error.message);
                            console.log('Error accessing media devices.', error);
                        });
                    })
                    .catch(function(error){
                        console.log(error);
                    });