Advertisement
WildWolvesMedia

Audio Effect Play Button jQuery

Oct 4th, 2019
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.49 KB | None | 0 0
  1. <div id="play">Play</div>
  2. <audio preload="auto" id="chirp"><source src="/chirp.mp3" type="audio/mpeg"></audio>
  3. <script>
  4. $(document).ready(function() {
  5.   $("#play").on('click',function() {
  6.       if(!muted) {
  7.     var btn = document.getElementById("chirp");
  8.     btn.play().then(function() {
  9.             console.log('play');
  10.         // Promise OK, Automatic playback started!
  11.         }).catch(function(error) {
  12.             console.log(error);
  13.         // Promise not OK, Automatic playback failed.
  14.         });
  15.       }
  16.     });
  17. });
  18. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement