Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div id="play">Play</div>
- <audio preload="auto" id="chirp"><source src="/chirp.mp3" type="audio/mpeg"></audio>
- <script>
- $(document).ready(function() {
- $("#play").on('click',function() {
- if(!muted) {
- var btn = document.getElementById("chirp");
- btn.play().then(function() {
- console.log('play');
- // Promise OK, Automatic playback started!
- }).catch(function(error) {
- console.log(error);
- // Promise not OK, Automatic playback failed.
- });
- }
- });
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement