Page 1 of 1

play mp3 sound after 1 minute (cross browser and mobile )

Posted: Thu Sep 22, 2016 9:04 pm
by cjkeane
Hi everyone,
I am having a bit of difficulty making sure a sound (for new email notification for eg) is heard. It seems to work in google chrome, but not on mobile devices, ipad and it seems other programs on the computer could affect playback . this is what i have. what would you suggest? thanks.

I call this function after the page refreshes and a db query checks for any unread messages. Thanks for any assistance..

Code: Select all

<script type="text/javascript">function refreshPage(){setTimeout('window.location.href=window.location.href',60000);}</script>
<script language="javascript" type="text/javascript">
	 function play_sound() {
		var audioElement = document.createElement('audio');
        audioElement.setAttribute('src', 'music/ding.mp3');
        audioElement.setAttribute('autoplay', 'autoplay');
        audioElement.load();
        audioElement.play();
    }
	function Delay_sound() {
		setTimeout("play_sound()", 45000);
	}
</script>

Re: play mp3 sound after 1 minute (cross browser and mobile

Posted: Thu Sep 22, 2016 10:58 pm
by Christopher
iOS and some other mobile devices will not play audio/video in the browser unless initiated by a user click. Desktop browsers do not have this limitation. Only iOS apps can play audio not preceded by user input. Frustrating but that's Apple.