I am currently working on an application using HTML and JavaScript which is accessed from an Android app through a webview. I have a specific requirement where, upon pressing a button in the webview, a beep sound should be played using a JavaScript function called createOscillator. Interestingly, the sound plays fine in the browser (Mozilla) on my PC but not on the mobile device via the webview (I tested it on Android 8.0.0 OS, Samsung Galaxy A5 (2017)). Why is there no sound on the cellphone? Thank you for your help...
HTML
<button name="zavrsisnimi" id="zavrsisnimi1" type="submit" onClick="zavrsisnimi(this.id)"
style="width:100%; height:100%; margin:0%;
background-color:white; font-size:xx-large; font-size:2.0vw; font-size:3.0vh;" >
SEND
</button>
JavaScript
function zavrsisnimi(id)
{
var y;
y="yes";
navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate;
if (navigator.vibrate)
{
alert("I am using navigator vibrate");
beep2();
}
window.open('/somefolder/file2?zavrsisnimi='+y,'_self');
return;
}
function beep2()
{
a=new (AudioContext || webkitAudioContext);
beepc(300,520,2000);
function beepc(vol, freq, duration)
{
v=a.createOscillator();
u=a.createGain();
v.connect(u);
v.frequency.value=freq;
v.type="square";
u.connect(a.destination);
u.gain.value=vol*0.01;
v.start(a.currentTime);
v.stop(a.currentTime+duration*0.001);
}
}
In Android Studio AndroidManifest.xml
<uses-permission android:name="android.permission.VIBRATE" />