Re: [mediacapture-screen-share] Either fully support or remove audio capture entirely: "MAY" re audio capture is ambiguous (#140)

@aboba 

> AFAIK, only system-wide audio capture has been implemented (in Chromium)

Not by default at *nix. 

It is not possible to get system wide audio output at Chromium at *nix without setting `Monitor of <device>` either at PulseAudio sound settings GUI or `~/.asoundrc` (untested).

Firefox _does_ list `Monitor of <device>` at `getUserMedia()`, see https://github.com/web-platform-tests/wpt/issues/23084, linked to at https://github.com/w3c/mediacapture-screen-share/issues/100#issuecomment-626197169.

Consider 

```
let constraints = new Map([
    ['getDisplayMedia', { audio: true, video: true }],
    ['getUserMedia', { audio: true }],
  ]),
  audioTrack,
  videoTrack,
  recorder;
navigator.mediaDevices.ondevicechange = e => console.log(e);
navigator.mediaDevices
  .getDisplayMedia(constraints.get('getDisplayMedia'))
  .then(async stream => {
    try {
      let audioStream;
      console.log(stream.getTracks());
      [videoTrack] = stream.getVideoTracks();
      if (
        constraints.get('getDisplayMedia').video &&
        stream.getAudioTracks().length === 0
      ) {
        const devices = await navigator.mediaDevices.enumerateDevices();
        console.log(devices);
        const audioDevice = devices.find(
          ({ kind, label }) =>
            kind === 'audiooutput' || (label && label.includes('Monitor'))
        );
        if (audioDevice) {
          constraints.get('getUserMedia').audio = {
            audio: { exact: { deviceId: audioDevice.groupId } },
          };
          audioStream = await navigator.mediaDevices.getUserMedia(
            constraints.get('getUserMedia')
          );
          [audioTrack] = audioStream.getAudioTracks();
          if (audioTrack) {
            stream.addTrack(audioTrack);
            recorder = new MediaRecorder(stream);
            recorder.ondataavailable = e => {
              console.log(URL.createObjectURL(e.data));
              audioTrack.stop();
              videoTrack.stop();
            };
            recorder.start();
            setTimeout(() => {
              recorder.stop();
            }, 10000);
          }
        }
      }
    } catch (e) {
      console.error(e);
    }
  });

```

unless the user physically selects `Monitor of <device>` _outside_ of the browser, specifically, _only_ **_during_** recording of initial `MediaStream` using `MediaRecorder` as a workaround, to persist that device now being set  as  default whenever `getUserMedia()` is called after that, unless changed at GUI or native code, the audio track will _always_ be microphone _input_, not system wide or application specific audio output, because _after_ the recording has stopped the user no longer has that option.

The fix here is very simple. Either remove MAY language to not compel implementers to be in conformance with this specification re audio capture at all, or substitute MUST for MAY to compel implementers to allow selection of `Montitor of <device>` at `getUserMedia()` and `getDisplayMedia()` prompt (and constraints) at Chromium.

If you are aware of a canonical means  to select system wide audio output at Chromium/Chrome _other than_ the procedure described above, kindly  share the complete procedure here. As it stands, after experimenting and testing various approaches, it appears to be impossible to capture audio output at Chromium using an official API.
![Screenshot_2020-05-09_20-03-05](https://user-images.githubusercontent.com/4174848/81483868-be7a6800-9230-11ea-9fe7-fc4082f2f299.png)
![Screenshot_2020-05-09_20-04-00](https://user-images.githubusercontent.com/4174848/81483870-bf12fe80-9230-11ea-8cbd-77c1f69507c4.png)



-- 
GitHub Notification of comment by guest271314
Please view or discuss this issue at https://github.com/w3c/mediacapture-screen-share/issues/140#issuecomment-626228914 using your GitHub account

Received on Saturday, 9 May 2020 20:07:52 UTC