I am trying to play audio automatically based on condition when I get ajax response. I receive response.code == 1 from my ajax call, but it does not play the audio.
<audio id="myAudio" >
  <source src="{{asset('Dashboard/alarm.mp3')}}" type="audio/mpeg">
</audio> 
$.ajax({
  url: '{{url('/')}}',
  type: 'POST',
  data: {
    _token: _token
  },
  dataType: 'json',
  success: function(response) {
    if (response.code == 1) {
      playAudio();
    }
  }
});
function playAudio() {
  var x = document.getElementById("myAudio");
  x.play();
}
 
     
     
    