Bug 190410

Summary: REGRESSION (Safari 12): User gesture after few seconds leads to audio context resuming but no sound
Product: WebKit Reporter: Jordan Nelson <shortsands.ceo>
Component: Web AudioAssignee: Nobody <webkit-unassigned>
Status: RESOLVED INVALID    
Severity: Normal CC: bfulgham, jeremyj-wk, jer.noble, shortsands.ceo, webkit-bug-importer
Priority: P2 Keywords: InRadar, Regression
Version: WebKit Nightly Build   
Hardware: Mac   
OS: macOS 10.13   
Attachments:
Description Flags
webaudio-after-5s.html none

Description Jordan Nelson 2018-10-09 13:42:37 PDT
On Safari 12, I am trying everything I can to get audio to have sound.  It was working on Safari 11, but not on Safari 12.
In the app, calling resume() on the audioContext after a user interaction gets the audio context out of suspended and into running in all cases.  So I am assuming that it is "allowed to start" per Web Audio API.
However, if user interaction is within ~5 seconds of loading the page, sound comes out.  If after 5 seconds, no sound.
Thanks.

    function fixAudioContext() {
      
      console.log("1: " + audioContext.state);
      
      return audioContext.resume().then(function() {
        
        console.log("2: " + audioContext.state);
        
        var buffer = audioContext.createBuffer(1, 1, 22050);
        var source = audioContext.createBufferSource();
        source.buffer = buffer;
        // Connect to output (speakers)
        source.connect(audioContext.destination);
        // Play sound
        if (source.start) {
          source.start(0);
        } else if (source.play) {
          source.play(0);
        } else if (source.noteOn) {
          source.noteOn(0);
        }
        
        console.log("3: " + audioContext.state);
        
        audioContextDeferred.resolve(audioContext.state);
      })
      .catch(function() {
      });
    }

After 5 seconds console still prints, "1: suspended, 2: running, 3: running" but no sound.  The creating buffer stuff is an attempt to play a silent sound to warm up the context.  Honestly just a shot in the dark.
Comment 1 Radar WebKit Bug Importer 2018-10-10 16:25:25 PDT
<rdar://problem/45177309>
Comment 2 Jer Noble 2018-10-10 17:47:23 PDT
Created attachment 352003 [details]
webaudio-after-5s.html

Hi Jordan,

I fleshed out your example a bit, and used an oscillatorNode instead of a audioSourceBufferNode, just so I could hear the results, and it definitely seems to be audible, no matter how long I wait before hitting the button. Could you post a more complete version of your test case?
Comment 3 Jordan Nelson 2018-10-11 12:45:02 PDT
Jer Noble,

  I setup a mini example demo myself to try to reproduce, but it was working as expected.  I finally found the bug in my application code that was causing the strange time dependent behavior.  This ticket can be closed out because there is nothing wrong.  Thank you so much for responding.

Sincerely,
   Jordan