1<html> 2<!-- 3 ~ Copyright 2024 The Android Open Source Project 4 ~ 5 ~ Licensed under the Apache License, Version 2.0 (the "License"); 6 ~ you may not use this file except in compliance with the License. 7 ~ You may obtain a copy of the License at 8 ~ 9 ~ http://www.apache.org/licenses/LICENSE-2.0 10 ~ 11 ~ Unless required by applicable law or agreed to in writing, software 12 ~ distributed under the License is distributed on an "AS IS" BASIS, 13 ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ~ See the License for the specific language governing permissions and 15 ~ limitations under the License. 16 --> 17<head> 18</head> 19<body> 20<noscript><p><strong>JavaScript was not enabled. Sound will not generate.</strong></p></noscript> 21<input id="play" type="checkbox" onchange="soundToggled()" checked><label>Generate tone in web content</label> 22<p> 23 This web content will immediately generate a continuous 440Hz tone at 50% volume (without first 24 needing user interaction). Check device volume settings as appropriate. 25</p> 26<p> 27 By default, the WebView loading this page will be muted, so a tone should not be heard until it 28 is unmuted. 29</p> 30<script defer type="text/javascript"> 31 const play = document.getElementById("play"); 32 const audioCtx = new window.AudioContext; 33 const gain = audioCtx.createGain(); 34 gain.connect(audioCtx.destination); 35 let oscillator = null; 36 37 function soundToggled() { 38 if (play.checked) { 39 oscillator = audioCtx.createOscillator(); 40 oscillator.type = 'sine'; 41 oscillator.frequency.setValueAtTime(440, audioCtx.currentTime); 42 gain.gain.setValueAtTime(0.5, audioCtx.currentTime); 43 oscillator.connect(gain); 44 oscillator.start(); 45 } else { 46 if (oscillator) { 47 oscillator.stop(); 48 oscillator = null; 49 } 50 } 51 } 52 53 soundToggled(); 54</script> 55</body> 56</html>