Autoplay on audio after consultation

0

I've been having a very serious problem with my system. It turns out that I have a jquery script that simply, after a query in the database, plays an audio in the browser.

$('body').append('<embed src="audio/found.mp3" hidden="true" autostart="true" type="audio/mp3">');

It turns out that if the tab is not focused on the browser, ie if I do not have the site tab open, or are in another program, the audio does not play, and I need it to play ALWAYS, NO EXCESSIONS . The site already has HTTPS (which I thought was a limiter of this function), but even then it will not. Is there any library to help me with this? What guarantees that the audio will always be played?

Thank you in advance.

    
asked by anonymous 26.08.2018 / 00:35

1 answer

-1

I do not know how you did the code, but I did a test here and it worked normally, even though it was on another tab:

<audio id="myaudio" controls style="display: none;">
    <source src="starwars.mp3" type="audio/mp3">
</audio>
<script>
  $.post({
  url : "teste.php",
  data : {
  f : "f"
  },
  success: function(msg){
  document.getElementById("myaudio").play();
  }
  });
<script>

    
26.08.2018 / 03:44