Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <body></body> | |
| 3 <script> | |
| 4 function synthesizeClick(callback) { | |
| 5 var button = document.createElement('input'); | |
| 6 button.type = 'button'; | |
| 7 button.value = 'click me'; | |
| 8 button.onclick = callback; | |
| 9 document.body.appendChild(button); | |
| 10 | |
| 11 if ('eventSender' in window) { | |
| 12 var boundingRect = button.getBoundingClientRect(); | |
| 13 var x = boundingRect.left + boundingRect.width / 2; | |
| 14 var y = boundingRect.top + boundingRect.height / 2; | |
| 15 | |
| 16 eventSender.mouseMoveTo(x, y); | |
| 17 eventSender.mouseDown(); | |
| 18 eventSender.mouseUp(); | |
| 19 } | |
| 20 // else, the user should manually click. | |
| 21 } | |
| 22 | |
| 23 // AudioContext will start as suspended when lacking a user gesture. | |
| 24 var audioContext = new AudioContext(); | |
| 25 window.parent.postMessage({ msg: 'initialState', value: audioContext.state }, | |
| 26 '*'); | |
| 27 | |
| 28 // OfflineAudioContext has no user gesture requirement but is always suspended. | |
| 29 var offlineAudioContext = new OfflineAudioContext(1, 512, 3000); | |
| 30 window.parent.postMessage({ msg: 'initialOfflineState', | |
| 31 value: offlineAudioContext.state }, '*'); | |
| 32 | |
| 33 // Calling 'resume()' will fail to start the AudioContext. | |
| 34 audioContext.resume(); | |
| 35 window.parent.postMessage({ msg: 'afterResume', value: audioContext.state }, | |
| 36 '*'); | |
| 37 | |
| 38 // Calling 'start()' will fail to start on a Node the associated AudioContext. | |
|
Raymond Toy
2016/09/26 16:09:54
How is this determined here (that start() failed t
mlamouri (slow - plz ping)
2016/09/26 17:01:24
I mean to start an AudioContext. Below, it's testi
| |
| 39 var oscillator = audioContext.createOscillator(); | |
| 40 oscillator.type = 'square'; | |
| 41 oscillator.frequency.value = 2000; | |
| 42 oscillator.connect(audioContext.destination); | |
| 43 oscillator.start(); | |
| 44 window.parent.postMessage({ msg: 'afterOscillator', value: audioContext.state }, | |
| 45 '*'); | |
| 46 | |
| 47 var otherAudioContext = new AudioContext(); | |
| 48 | |
| 49 synthesizeClick(_ => { | |
| 50 // Calling 'resume()' from a click event will start the audio context. | |
| 51 audioContext.resume(); | |
| 52 window.parent.postMessage({ msg: 'stateAfterClick', | |
| 53 value: audioContext.state }, '*'); | |
| 54 | |
| 55 window.parent.postMessage({ msg: 'stateOtherContextAfterClick', | |
| 56 value: otherAudioContext.state }, '*'); | |
| 57 | |
| 58 synthesizeClick(_ => { | |
| 59 var oscillator = otherAudioContext.createOscillator(); | |
| 60 oscillator.type = 'square'; | |
| 61 oscillator.frequency.value = 2000; | |
| 62 oscillator.connect(otherAudioContext.destination); | |
| 63 // Calling 'start()' from a click event will not start the audio context. | |
| 64 oscillator.start(); | |
| 65 | |
| 66 window.parent.postMessage({ msg: 'stateOtherContextAfterSecondClick', | |
| 67 value: otherAudioContext.state }, '*'); | |
| 68 | |
| 69 synthesizeClick(_ => { | |
| 70 // Creating an AudioContext from a click event will start it. | |
| 71 var lastAudioContext = new AudioContext(); | |
| 72 window.parent.postMessage({ msg: 'stateCreatedAfterClick', | |
| 73 value: lastAudioContext.state }, '*'); | |
| 74 | |
| 75 window.parent.postMessage({ msg: 'done' }, '*'); | |
| 76 }); | |
| 77 }); | |
| 78 }); | |
| 79 </script> | |
| OLD | NEW |