Bug 238456 - HTMLMediaElement plays MediaStream with 'muted' attribute, but plays sounds again after getUserMedia again
Summary: HTMLMediaElement plays MediaStream with 'muted' attribute, but plays sounds a...
Status: RESOLVED DUPLICATE of bug 235544
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: Safari 15
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-28 07:50 PDT by Yuwei Zhang
Modified: 2022-03-28 08:00 PDT (History)
2 users (show)

See Also:


Attachments
sample-test (1.23 KB, text/html)
2022-03-28 07:50 PDT, Yuwei Zhang
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yuwei Zhang 2022-03-28 07:50:58 PDT
Created attachment 455918 [details]
sample-test

Device: 
iOS 15.4   iPhone 12
iOS 15.3.1 iphoen 13

Browser:
safari


Steps to reproduce:

1. video element with 'muted' 'playsinline' 'autoplay'
   
2. get MediaStream wih getUserMedia({ audio: true, video: { facingMode: 'user' } }) with front camera and play wih video element

   localStream = await navigator.mediaDevices.getUserMedia({ audio: true, video: { facingMode: 'user' } });
   video.srcObject = localStream;

3. get MediaStream with getUserMedia({ audio: false, video: { facingMode: 'environment' } }) with back camera and play
    
   backCameraStream = await navigator.mediaDevices.getUserMedia({ audio: false, video: { facingMode: 'environment' } });

   const originVideoTrack = localStream.getVideoTracks()[0];
   localStream.removeTrack(originVideoTrack);
   localStream.addTrack(backCameraStream.getVideoTracks()[0]);

Actual result: you can hear the sound
Expected result: video can't play any sound

Sample test:
https://zhangyuwei-1254112368.cos.ap-guangzhou.myqcloud.com/safari-test-muted/index.html

1. click on the first button
   you can't hear any sound

2. click on the second button
   you can hear the sound


The code is listed below:

```
let video = document.getElementById('localStream');
  let btnA = document.getElementById('btnA');
  let btnB = document.getElementById('btnB');
  let localStream, backCameraStream;

  btnA.addEventListener('click', async () => {
    localStream = await navigator.mediaDevices.getUserMedia({ audio: true, video: { facingMode: 'user' } });
    video.srcObject = localStream;
  });

  btnB.addEventListener('click', async () => {
    backCameraStream = await navigator.mediaDevices.getUserMedia({ audio: false, video: { facingMode: 'environment' } });

    const originVideoTrack = localStream.getVideoTracks()[0];
    localStream.removeTrack(originVideoTrack);
    localStream.addTrack(backCameraStream.getVideoTracks()[0]);
  });
```
Comment 1 youenn fablet 2022-03-28 08:00:39 PDT
Thanks for the report, I think this is a dupe of bug 235544.

*** This bug has been marked as a duplicate of bug 235544 ***