Bug 175412 - WebAudio does not output sound on iOS without user gesture
Summary: WebAudio does not output sound on iOS without user gesture
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Audio (show other bugs)
Version: Other
Hardware: iPhone / iPad iOS 11
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-08-09 18:05 PDT by Andrew Morris
Modified: 2017-08-10 17:41 PDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Morris 2017-08-09 18:05:17 PDT
No sound resulting from this code, also no error is thrown:

https://output.jsbin.com/mogudag

'use strict';

const handleError = (e) => {
  const pre = document.createElement('pre');
  pre.style.color = 'red';
  pre.textContent = `Error: ${e}\n.message: ${e.message}\n.stack: ${e.stack}`;
  document.body.appendChild(pre);
};

window.addEventListener('error', ({ error }) => handleError(error));
window.addEventListener('unhandledrejection', ({ reason }) => handleError(reason));

(async () => {
  try {
    await new Promise(resolve => window.addEventListener('load', resolve));
  
    const ctx = new (window.webkitAudioContext || window.AudioContext)();

    const oscNode = ctx.createOscillator();

    oscNode.connect(ctx.destination);
    oscNode.start();
  } catch (e) {
    handleError(e);
  }
})();
Comment 1 Andrew Morris 2017-08-09 18:06:00 PDT
Tested on iPhone with iOS beta 4 and iPad with iOS beta 5.
Comment 2 Radar WebKit Bug Importer 2017-08-09 19:56:54 PDT
<rdar://problem/33818985>
Comment 3 Alexey Proskuryakov 2017-08-10 15:58:12 PDT
Does this start to work for you if triggered from a user interaction (tap?).
Comment 4 youenn fablet 2017-08-10 15:59:12 PDT
For instance, https://output.jsbin.com/yuhobukuji
Comment 5 Andrew Morris 2017-08-10 17:41:18 PDT
Ah it does work with user interaction. Didn't think that kind of restriction applied for web audio. Thanks.