<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
$('#play')[0].click();//initial click on 'play' button to play music which doesn't seem to be working...
$('#play').on('click',function(){
$("#Audio1")[0].play();
})
});
</script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<audio id="Audio1" controls="controls"
src="http://themes.rascals.eu/eprom/dark/wp-content/uploads/2012/11/Madoff-Bomp.mp3" type="audio/mp3" >
</audio>
HTML5 Audio is required for this example.
<input type="button" id="play" value="play" />
</body>
</html>
I want to trigger a click event on the "Play" button to play the music.
I need to do like this way as 'Autoplay' doesn't work on mobile devices.
Due to data concern, it is blocked by default.
I found this article, http://makandracards.com/makandra/13893-autoplay-html5-audio-in-chrome-for-android-mobile-safari-in-ios and turned out he is right as if I hit this play button on my phone, music is playing as expected.
I want to trigger this button to be clicked after the page gets loaded. It is not working but if I run the same bit of js IN CONSOLE it is working.
Edit 1
Per suggestion given in comment I have tried this but still no luck.
$(document).ready(function() {
$('#play').on('click', function() {
$("#Audio1")[0].play();
})
$('#play')[0].click(); //initial click on 'play' button to play music which doesn't seem to be working...
});