Bug 196539 - Cannot automatically output audio to loudspeaker for Safari in iOS 12.2
Summary: Cannot automatically output audio to loudspeaker for Safari in iOS 12.2
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Service Workers (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-04-03 07:51 PDT by youenn fablet
Modified: 2021-10-29 00:01 PDT (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2019-04-03 07:51:50 PDT
See https://github.com/webrtc/samples/issues/1186:

access https://webrtc.github.io/samples/src/content/peerconnection/audio/,
click the Call button, authorize access to your microphone
you should see the red microphone icon being displayed on the upper left, statistics charts flowing, and hear your own audio input being played back in the internal phone speaker
now pause you local audio stream (by clicking the corresponding <audio /> tag, or mute/unmute yourself by clicking the red microphone icon, and the remote audio will be played back in the loudspeaker.
Comment 1 Radar WebKit Bug Importer 2019-04-03 07:53:09 PDT
<rdar://problem/49558299>
Comment 2 Shu Muto 2020-12-22 18:23:34 PST
I found that redoing `srcObject = stream` for audio / video tag also be a workaroud.
However, JavaScript can not detect when should do these workarounds. There is no choice but to judge by the user, and implementation such as "press this button if you can't hear" is not cool extreamly.
Comment 3 David Gölzhäuser 2021-09-22 02:34:34 PDT
I stumbled over the same issue, however I am only able to reproduce this on iPhones, iPads work fine

Tested on iOS 15 RC
Comment 4 Phong Le 2021-09-22 06:48:32 PDT
On iOS 15, in a call of WebRTC the audio so low and cannot listen. It did not happen on iOS 14. Please help to fix
Comment 5 David Gölzhäuser 2021-09-22 23:13:56 PDT
I worked around this issue by applying the following procedure (Cordova based Application)

• Starting a WebRTC Audio Connection
    • `getUserMedia` has been replaced with a native implementation to work around an issue I have regarding getting a mute MediaStream on iOS 15, also this works around the constant Microphone permission popups on older iOS devices not being able to override the permission handling in the using the new method `requestMediaCapturePermissionForOrigin` in iOS 15
• Wait until the remote peer sends the audio track to the client device
• Hangup
• Reestablish the WebRTC Audio Connection

This procedure only needs to be done once per Application live cycle.
Comment 6 David Gölzhäuser 2021-09-22 23:16:00 PDT
(In reply to Phong Le from comment #4)
> On iOS 15, in a call of WebRTC the audio so low and cannot listen. It did
> not happen on iOS 14. Please help to fix

I also first suspected that the Volume is very low, but after some careful listening I noticed that the audio just was emitted from the earpiece of the iPhone, not from the speaker in the bottom.

In addition I noticed that the issue isn't present when starting another call in the same live cycle of the App/Website.
Comment 7 Phong Le 2021-09-23 01:25:57 PDT
In my case, the call uses bottom speaker with very low volume level on iPhone. iPad also but a bit. Now, my customers must use headphone when calling. Therefore, I thought the reason Apple did this one is to sell Airpod :)
Comment 8 Phong Le 2021-09-23 01:28:27 PDT
(In reply to David Gölzhäuser from comment #5)
> I worked around this issue by applying the following procedure (Cordova
> based Application)
> 
> • Starting a WebRTC Audio Connection
>     • `getUserMedia` has been replaced with a native implementation to work
> around an issue I have regarding getting a mute MediaStream on iOS 15, also
> this works around the constant Microphone permission popups on older iOS
> devices not being able to override the permission handling in the using the
> new method `requestMediaCapturePermissionForOrigin` in iOS 15
> • Wait until the remote peer sends the audio track to the client device
> • Hangup
> • Reestablish the WebRTC Audio Connection
> 
> This procedure only needs to be done once per Application live cycle.

Wow. Thank for you share :)
Comment 9 David Gölzhäuser 2021-09-28 01:55:57 PDT
(In reply to Phong Le from comment #4)
> On iOS 15, in a call of WebRTC the audio so low and cannot listen. It did
> not happen on iOS 14. Please help to fix

I revisited the issue today and noticed that I had a wrong behaviour when receiving the PeerConnections tracks.

First the PeerConnections method `ontrack` gets called with a MediaStream containing just the VideoTrack, I simply attached the MediaStream to the `srcObject` of the Video Tag, then I receive the AudioTrack from the same call, I then created a new Audio Tag and added the received MediaStream to the Audio Tags `srcObject` which is wrong as it will be played through the earpiece.

What I had done to fix this is I just update the video tags `srcObject` everytime the PeerConnections `ontrack` method gets called. I assume that way the video and audio are handled in the same "AudioSession" and thus get played on the same Speaker output.
Comment 10 Les 2021-09-28 11:15:14 PDT
(In reply to Phong Le from comment #4)
> On iOS 15, in a call of WebRTC the audio so low and cannot listen. It did
> not happen on iOS 14. Please help to fix

We're noticing the same issue with our web app and can even reproduce with Apple's own FaceTime web app (facetime.apple.com) 

We've tried updating the `srcObject` among other things but haven't had any luck.

Here's a link to the bug we've opened that has FaceTime repro steps:
https://bugs.webkit.org/show_bug.cgi?id=230902
Comment 11 David Gölzhäuser 2021-10-01 08:31:43 PDT
I have to correct my previous comments. It is NOT working. I thought it does because a my college increased the volume of the webRTC peer.

I think the issue lies on the srcObject. I can play AudioTags created like `new Audio(URL)` just fine, however when creating an AudioTag and setting the srcObject property the audio is played through the earpiece.

Can anyone reproduce this?

I am just fighting in converting a MediaStream to a Blob by sub-sequentially sampling the MediaStream with a MediaRecorder, then converting the blob to a dataURI and setting it as a src to an AudioTag.
Comment 12 David Gölzhäuser 2021-10-05 04:04:52 PDT
[UPDATE]

I figured out a temporary Workaround.

Here is my use case:
Cordova Based iOS Application which initially receives a VideoTrack from the RTCPeerConnection. Then the user can decide to start a voice call which asks the user for the microphone access and adds the Microphone track to the RTCPeerConnection, this will result in receiving the remote peers microphone stream. However with the drawback of the reduced volume due to the wrong speaker selection.

I worked around it by first add a MediaStream's AudioTrack (created with `audioContext.createMediaStreamDestination().stream`) to the RTCPeerConnection. Then when receiving the remote peers microphone stream the user is asked for the microphone permission using `getUserMedia`. When the user accepts and the microphone stream is available I simply replace the aforementioned track with the microphone track using RTCRtpSender function `replaceTrack`. (The `RTCRtpSender` is returned from the `RTCPeerConnection` method `addTrack`)

However this fix only works once per app livecycle. I am guessing that the `AVAudioSession` gets confused, I tried to reset it using a Cordova Plugin, but it didn't yield the wanted results.
Comment 13 Phong Le 2021-10-28 22:41:35 PDT
Using AudioContext is bad solution. If the user plug a headset and we still keep gain 10. Then, it would be very very high volume :(. We cannot do anything here because we cannot detect when users plug their headset. We must wait for fixing this issue
Comment 14 David Gölzhäuser 2021-10-28 23:58:21 PDT
Please create a Feedback on Apples Feedback App to gain more attention for this issue. I did create a Feedback on 3rd of August and it is ignored ever since
Comment 15 Phong Le 2021-10-29 00:01:11 PDT
(In reply to David Gölzhäuser from comment #14)
> Please create a Feedback on Apples Feedback App to gain more attention for
> this issue. I did create a Feedback on 3rd of August and it is ignored ever
> since

Actually, it has been assigned to fix at https://bugs.webkit.org/show_bug.cgi?id=230902