lundi 16 février 2015

JavaScript audio will not play when tab is not in focus

I have a webpage that uses JQuery Countdown and I have an audio clip that plays when the coundown reaches zero.


Here's the relevant code:



<script>
$(function (){
$('#Timer1Timer').countdown({until: +(28800), onExpiry: play_single_sound});
$('#Timer2Timer').countdown({until: +(172800), onExpiry: play_single_sound});
$('#Timer3Timer').countdown({until: +(10), onExpiry: play_single_sound});
});
function play_single_sound() {
document.getElementById('audiotag1').play();
}
</script>
<audio id="audiotag1" src="audio/alert.wav" preload="auto"></audio>


The audio plays just fine when I have the page open in it's own window and I'm using a separate window to view another page. However, if I have a different tab open and active in the same window, the audio will not play when the countdown completes.


Any sort of assistance or explanation would be wonderful!


Aucun commentaire:

Enregistrer un commentaire