Bug 232640 - AudioContext stops playing when unplugging wired headphones from iOS devices
Summary: AudioContext stops playing when unplugging wired headphones from iOS devices
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Audio (show other bugs)
Version: Safari 15
Hardware: iPhone / iPad Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-11-02 14:42 PDT by Kyu Simm
Modified: 2022-11-29 15:27 PST (History)
13 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kyu Simm 2021-11-02 14:42:46 PDT
Problem:
- AudioContext stops playing when unplugging wired headphones from iOS devices.


Steps to Reproduce:

1. Do not plug wired headphones yet.
2. Open https://codepen.io/simmkyu/pen/xxLPNqe in iOS Safari or iOS Chrome.
3. Choose "Play OscillatorNode" that plays the 440 Hz tone using Web Audio nodes and HTMLAudioElement.
4. Plug wired headphones into your iOS device. You can still hear the tone from your headphones.
5. Unplug wired headphones from your iOS device. Go to the "Actual Results" section.


Steps to Reproduce 2 (the same code without using CodePen):

1. Connect your iOS device to macOS.
2. Open any website in iOS Safari. Open the Safari Web Inspector to inspect the website.
3. Run the following script in the console. The script plays the 440 Hz tone using Web Audio nodes and HTMLAudioElement.
  ```
  (async function () {
    // Allow this website to play HTMLAudioElement.
    await navigator.mediaDevices.getUserMedia({ audio: true });

    // OscillatorNode => GainNode => MediaStreamAudioDestinationNode
    const audioContext = new (window.AudioContext || window.webkitAudioContext)();
    const destinationNode = audioContext.createMediaStreamDestination();
    const gainNode = audioContext.createGain();
    gainNode.gain.value = 0.1;
    gainNode.connect(destinationNode);
    const oscillatorNode = audioContext.createOscillator();
    oscillatorNode.frequency.value = 440;
    oscillatorNode.connect(destinationNode);
    oscillatorNode.start();

    // MediaStreamAudioDestinationNode => HTMLAudioElement
    const audio = document.createElement('audio');
    document.body.appendChild(audio);
    audio.srcObject = destinationNode.stream;
    audio.play();
  })();
  ```
4. Plug wired headphones into your iOS device. You can still hear the tone from your headphones.
5. Unplug wired headphones from your iOS device.


Actual Results:
- You cannot hear the tone from your iOS device's speakers.


Expected Results:
- You should continue hearing the tone from your iOS device's speakers.


Build:
- iOS 15.0 and iOS 15.1
- ioS Safari 604.1
- iOS Chrome 95.0.4638.50


Additional Information:
- Important: iOS Safari or iOS Chrome plays the tone again if you go to the Home screen and return to the browser app. After you complete the "Steps to Reproduce" section, try to go to the Home screen (or another app) and reopen the browser app.
- In the "Steps to reproduce" sections, I used OscillatorNode and GainNode for demonstration, but the bug is reproducible only with the MediaStreamAudioDestinationNode. For example, you can connect your microphone's MediaStream to MediaStreamAudioDestinationNode. When unplugging your headphones, you will stop hearing your voice from HTMLAudioElement.
- I used Apple EarPods with Lightning Connector for testing.
- The bug does not occur on macOS Safari (15.0) and other desktop browsers. I tested it using MacBook Pro (16-inch, 2019), Big Sur 11.6.1, and Apple EarPods with 3.5mm Headphone Plug.
Comment 1 Radar WebKit Bug Importer 2022-11-29 15:27:08 PST
<rdar://problem/102787007>