Autoplay in audio after consultation

Asked

Viewed 39 times

0

I have a problem in my system. I happen to have a jQuery script that simply, after a database query, 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 guide is not focused on the browser, that is, if I’m not with the site tab open, or I’m in another program, the audio doesn’t play, and I need it to play at all times, without exceptions. The site already has HTTPS (which I thought was a limiter of this function), but even so, it won’t. Is there a library that helps me with this and ensures that the audio will always be played?

  • can be a browser policy, happens at all? why are you using <embed> and not the tag <audio>.

  • I already tried to use the audio and gave the same error. Then I changed the tag but same thing..

  • Vc is using setTimeout or setInterval?

  • No. The audio is played right after the ajax sequence.

  • Vitor, you managed to solve ?

1 answer

-1

I don’t know how you did the code, but I did a test here and it worked normally, even though it was in 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>

NOTE: For some reason if I use the Jquery selector "$" the "play()" function is not triggered.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.