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

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

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

Post 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');
	function Delay_sound() {
		setTimeout("play_sound()", 45000);
User avatar
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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.
Post Reply