I found that:
<!DOCTYPE html>
<html>
<head>
<script src='jQuery.js'></script>
<script>
$(document).ready(function(){
document.getElementById("asdf").play();
});
</script>
</head>
<body>
<audio src='music.m4a' id='asdf'></audio>
</body>
</html>
or
<!DOCTYPE html>
<html>
<head>
<script>
setTimeout('document.getElementById("asdf").play();',10000);
</script>
</head>
<body>
<audio src='music.m4a' id='asdf'></audio>
</body>
</html>
will not play the music on iPhone (of course above two works in normal computer), but writing
<!DOCTYPE html>
<html>
<body>
<audio src='music.m4a' id='asdf'></audio>
<a href='javascript:document.getElementById("asdf").play()'>dd</a>
</body>
</html>
and click on 'dd' will play the music.
My question is : how to automatically play the music right after the page is loaded (and 'ready' to play the music) in iPhone?
PS : I added setInterval('if($("#asdf").attr("readyState")) console.log(1);');
for check whether the sound is loaded, and I found that readyState
is changed right after I pressed 'dd'.