I'm trying to implement a button press sound using HTML5 <audio>
element and a javascript trigger. I am getting bit of a delay between when the button is pressed and when the sound plays. The sound is meant to be user feedback for a successful press so any delay is unacceptable.
The implementation works fine on all windows devices, but there is a varying amount of delay on any android device I've tested on.
HTML:
<audio id="button_click" preload="auto">
<source src="audio/button.mp3" type="audio/ogg">
</audio>
JS:
$scope.buttonClick = function(){
var audio = document.getElementById('button_click');
audio.load();
audio.play();
};
The extra audio.load(); line is a workaround for the problem of HTML5 audio elements only playing once on Android devices.
Any thoughts on a workaround? If there is no workaround, any thoughts on how to implement an audible feedback for button clicks in a browser based single page app?