I'm trying to autoplay an <audio>
element but still not working in IE, but working in other browsers. Please see my code below:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<audio id="effectTada">
<source src="https://www.soundeffectsplus.com/uploads/prod_audio/39472249_footsteps-running-on-road-03.mp3" type="audio/mpeg">
<source src="https://www.soundeffectsplus.com/uploads/prod_audio/39472249_footsteps-running-on-road-03.wav" type="audio/mpeg">
<source src="https://www.soundeffectsplus.com/uploads/prod_audio/39472249_footsteps-running-on-road-03.ogg" type="audio/ogg">
</audio>
<button type="button" class="play">Play</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(function(){
$(document).on('click', '.play', function(){
$('#effectTada').attr('autoplay', true);
});
});
</script>
</body>
</html>
Note: I know the wav
and ogg
is not working here, but I have a working of these 2. I also tried a lot of research about this topic.
Update:
$(document).on('click', '#completed', function(){
var urls = "some url";
$.ajax({
url: urls,
type: 'GET',
success: function(data){
$("#effectTada")
.attr('autoplay', true)
.get(0).play();
}
});
});