RESOLVED INVALID132852
WebAudio doesn't play sound following User Interaction on iOS+Safari
https://bugs.webkit.org/show_bug.cgi?id=132852
Summary WebAudio doesn't play sound following User Interaction on iOS+Safari
Hugo
Reported 2014-05-12 20:58:37 PDT
Hi team, I have implemented the WebAudio for Webkit, and could successfully run it on Android+Chrome, but can not run it on iPad/iPhone with Chrome and Safari I trigger the javascript code upon a user interaction (touch on the screen). The function does 1- creates the audio context (only once) if (window.webkitAudioContext) { myaudioContext = new webkitAudioContext(); } else if (window.AudioContext) { myaudioContext = new AudioContext(); } 2- on the same call, loads the sound sounds (only once, using a BufferLoader class (XHR, base64 MP3 files from local URL) onto an array called letters. 3- The function sets a repeatable timer (3 seconds) and returns from the function. 4- In parallel, the timer selects the song from the pre-loaded songs list and play the song using var source = myaudioContext.createBufferSource(); source.buffer = songs[random].buffer; source.connect(myaudioContext.destination); if (!source.start) source.start = source.noteOn; source.start(0); I tried adding the code below (thanks Jer) try{ myaudioContext.startRendering(); }catch (ex){}; but it did not help The code executes just fine, but no sound comes out of the speaker. The use case is fairly trivial. This works on all windows browsers (FF, Safari, Chrome), on Mac browsers (Chrome, Safari and Firefox) and mobile tablets with Chrome on Nexus/Android OS. => But it doesn't work on Safari and Chrome on iOS (iPad and iPhone). The parsing of the MP3 files work just fine, in fact, I can create an <audio> element in the HTML, and when I click on it, play the song just fine, so I believe the MP3 is encoded properly, and decoded by the context just fine. I am puzzled by this problem. Thank you for taking the time to help me. I'm attaching the test case here. Thank you for your support. Best regards Hugo PS: Sorry it took me a bit to log this case, so this might seem redundant with https://bugs.webkit.org/show_bug.cgi?id=132691
Attachments
Here is the test case for https://bugs.webkit.org/attachment.cgi?bugid=132852 (64.12 KB, application/zip)
2014-05-12 20:59 PDT, Hugo
no flags
Hugo
Comment 1 2014-05-12 20:59:36 PDT
Jer Noble
Comment 2 2014-05-14 00:07:07 PDT
Try calling `myaudioContext.startRendering();`from within initAudioContext(). initAudioContext() is called in response to a user interaction, whereas playSong() is called in response to a timer.
Hugo
Comment 3 2014-05-14 09:24:13 PDT
That did it. I'm not sure why I couldn't make it work in the first place. Thank you for your great help Best Hugo
Note You need to log in before you can comment on or make changes to this bug.