Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetDisplayMedia don't capture the audio from microphone #694

Closed
athina635 opened this issue May 5, 2020 · 16 comments
Closed

GetDisplayMedia don't capture the audio from microphone #694

athina635 opened this issue May 5, 2020 · 16 comments

Comments

@athina635
Copy link

athina635 commented May 5, 2020

Hello, I already read a lot of comments here about this topic but I really got more confused about that and how to use this.

I already use the getDisplayMedia() to share my screen and that worked as well but I just capture the audio from the system like audio from youtube ..etc but I couldn't capture the audio from the microphone.

any clear answer about that?
any suggestions on how to capture the microphone sound?

thank you.

@guest271314
Copy link

guest271314 commented May 6, 2020

but I just capture the audio from the system like audio from youtube ..etc

Do you mean getDisplayMedia() does capture audio, only in certain cases? Or, getDisplayMedia() does not capture audio at all?

but I couldn't capture the audio from the microphone.

You should be able to capture audio with getUserMedia(), add the corresponding track to the other MediaStream, if necessary add the tracks to a new MediaStream.

let audioTrack, videoTrack, stream; // define initial variable here for ability to call stop() on each track
navigator.mediaDevices.getDisplayMedia({video: true})
.then(async displayStream => {
    [videoTrack] = displayStream.getVideoTracks();
    const audioStream = await navigator.mediaDevices.getUserMedia({audio: true}).catch(e => {throw e});
    [audioTrack] = audioStream.getAudioTracks();
    // displayStream.addTrack(audioTrack); // do stuff
    // or 
    // stream = new MediaStream([videoTrack, audioTrack]); // do stuff
})
.catch(console.error);

@athina635
Copy link
Author

athina635 commented May 6, 2020

Do you mean getDisplayMedia() does capture audio, only in certain cases? Or, getDisplayMedia() does not capture audio at all?

No, but getDisplayMedia() can capture all audio from the system and not from the microphone.

I will test what you suggested to me.

can I play around the audio and the video? I mean when I would stop the video and let the audio play or the opposite?

@guest271314
Copy link

No, but getDisplayMedia() can capture all audio from the system and not from the microphone.

Can you kindly cite the primary source which lead you reach that conclusion?

I will test what you suggested to me.

can I play around the audio and the video? I mean when I would stop the video and let the audio play or the opposite?

Yes, that is the purpose of defining audioTrack and videoTrack at the first line of the code, see comment.

@athina635
Copy link
Author

athina635 commented May 7, 2020

that is my code as you suggest i just modify a little bit on it!

i arrived to share the video and the audio like that.

am I right for what I did?

what I notice is the audio in somehow in slow motion mode just a little bit.

let audioTrack, videoTrack, stream;

            navigator.mediaDevices.getDisplayMedia({
                    video: true
                })
                .then(displayStream => {


                    [videoTrack] = displayStream.getVideoTracks();

                    navigator.mediaDevices.getUserMedia({
                        audio: true
                    }).then((audioStream) => {
                        [audioTrack] = audioStream.getAudioTracks();
                        stream = new MediaStream([videoTrack, audioTrack]);

                        mediaStreamObj = stream;
                        video.srcObject = stream;
                        video.play();
                        video.volume = 0;
                       .
                       .

@guest271314
Copy link

am I right for what I did?

Not sure, it is your requirement.

what I notice is the audio in somehow in slow motion mode just a little bit.

This is probably not the best venue for that issue. That is probably not all of the code, correct? Both Firefox and Chromium have issues with audio or video synchronization when MediaSource is used with MediaStream (in brief see guest271314/MediaFragmentRecorder#8 (comment), https://gist.github.com/guest271314/c38042935db4e0131c1e0b68ca59f4ac#gistcomment-3241753). If you start a gist will try to help there.

@guest271314
Copy link

@athina635

No, but getDisplayMedia() can capture all audio from the system and not from the microphone.

What document precisely gave you that impression?

@athina635
Copy link
Author

@guest271314

What document precisely gave you that impression?

when I use that getDisplayMedia() in Chrome and select the option of sharing audio when a pop up appears to ask you which screen do you want to capture (Tab screen, fullscreen...etc). with that, I could display the audio for the other peer (the system audio and not the microphone).

@guest271314
Copy link

Which OS? AFAICT getDisplayMedia() does not include an audio track for any case at *nix.

@athina635
Copy link
Author

Which OS?

on windows chrome navigator with audio: true i could capture the audio of the system like i mean when i launch something on the PC i could stream that sound

@guest271314
Copy link

Is this issue resolved?

@athina635
Copy link
Author

i resolved the issue by tracking the audio alone and the video alone too like that i could capture the audio from the microphone and that what i want. but now if i want to stop the video track in any moment how can i do that?

PS: I'm using this code:

[videoTrack] = displayStream.getVideoTracks();

                    navigator.mediaDevices.getUserMedia({
                        audio: true
                    }).then((audioStream) => {
                        [audioTrack] = audioStream.getAudioTracks();
                        stream = new MediaStream([videoTrack, audioTrack]);

@jan-ivar
Copy link
Member

jan-ivar commented May 7, 2020

Hi @athina635 this place is for reporting issues with the spec. For user problems, please post a question on sites like https://stackoverflow.com/questions/tagged/webrtc instead. Thanks!

@jan-ivar jan-ivar closed this as completed May 7, 2020
@jigarshah13
Copy link

@athina635 Can you please tell me how have your recorded audio and video both using getDisplayMedia()?

I am able to record only video after selecting chrome tab where video is playing but audio from that video is not being recorded.

Can you give your code or any hint to record both audio and video from selected screen?

@andersoonluan
Copy link

but I just capture the audio from the system like audio from youtube ..etc

Do you mean getDisplayMedia() does capture audio, only in certain cases? Or, getDisplayMedia() does not capture audio at all?

but I couldn't capture the audio from the microphone.

You should be able to capture audio with getUserMedia(), add the corresponding track to the other MediaStream, if necessary add the tracks to a new MediaStream.

let audioTrack, videoTrack, stream; // define initial variable here for ability to call stop() on each track
navigator.mediaDevices.getDisplayMedia({video: true})
.then(async displayStream => {
    [videoTrack] = displayStream.getVideoTracks();
    const audioStream = await navigator.mediaDevices.getUserMedia({audio: true}).catch(e => {throw e});
    [audioTrack] = audioStream.getAudioTracks();
    // displayStream.addTrack(audioTrack); // do stuff
    // or 
    // stream = new MediaStream([videoTrack, audioTrack]); // do stuff
})
.catch(console.error);

It really helped me, thank you very much!

@AntonioMing
Copy link

AntonioMing commented May 9, 2021

i resolved the issue by tracking the audio alone and the video alone too like that i could capture the audio from the microphone and that what i want. but now if i want to stop the video track in any moment how can i do that?

PS: I'm using this code:

[videoTrack] = displayStream.getVideoTracks();

                    navigator.mediaDevices.getUserMedia({
                        audio: true
                    }).then((audioStream) => {
                        [audioTrack] = audioStream.getAudioTracks();
                        stream = new MediaStream([videoTrack, audioTrack]);

====
Hi @athina635 @andersoonluan
When the two sides communicate, the system’s playing voice will be mixed with the remote speaker’s voice at the same time. How to eliminate the remote speaker’s voice in the system’s playing voice in order to Let the remote speaker do not hear his own voice.

@MaciejWebWolf
Copy link

You can always set a microphone as a speakers output:

Go to [Control Panel] > [Hardware and Sound] > [Sound].
Find [Recording] tab > select [Microphone] > click [Properties] to access to the detail setting.
Click [Listen] tab and check [Listen to this device].
Tap [OK] or [Apply] to activate.

remember to check "share audio from computer" when a pop up appears

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants