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

I got an issue for capture audio from other applications while using GetDisplayMedia for screen sharing in a React Native app. #1002

Closed
priyankgandhi0 opened this issue May 6, 2024 · 3 comments

Comments

@priyankgandhi0
Copy link

priyankgandhi0 commented May 6, 2024

I've implemented screen sharing using WebRTC in my React Native app, but I'm encountering an issue where the audio from other apps, such as YouTube, is not being captured during screen broadcasting.

Below is the React Native code snippet I'm using for screen sharing:

const screenShareStreamRef = useRef();
const [screenShareStream, setScreenShareStream] = useState(null);
const screenShareVideoProducer = useRef();
const screenShareAudioProducer = useRef();

let audioTrack, videoTrack, screenstream;
  const startScreenStream = async () => {
    try {
      const displayStream = await mediaDevices.getDisplayMedia({ video: true });
      videoTrack = displayStream.getVideoTracks()[0];
  
      const audioStream = await mediaDevices.getUserMedia({ audio: true });
      audioTrack = audioStream.getAudioTracks()[0];
  
      // Combine video and audio tracks into a single MediaStream
      screenstream = new MediaStream([videoTrack, audioTrack]);
  
      screenShareStreamRef.current = screenstream;
      setScreenShareStream(screenstream);
            
    } catch (error) {
      console.error(error);
    }
})

For both iOS and Android, I've followed the setup provided in this guide: Link to the setup guide

Additionally, for iOS, I've added the necessary files into the project, as mentioned in the guide: Link to the files

I'm looking for insights or solutions on how to capture audio from other apps during screen sharing. Any help would be appreciated. Thank you!

@eladalon1983
Copy link
Member

You appear to be asking for screen-sharing video (getDisplayMedia) but microphone-derived audio (getUserMedia). You should instead call getDisplayMedia({video: true, audio: true}).

Note that availability of video/audio for screen-sharing differs by (1) browser, (2) OS and (3) what the user ends up sharing (tab/window/screen). For example, Chrome does not currently support screen-sharing on Android. Such issues belong in the browser's bug-tracker rather than here, though.

@alvestrand
Copy link
Contributor

Closing as "not a problem with the spec".

@priyankgandhi0
Copy link
Author

@eladalon1983 I have already do this but the same issue.

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

3 participants