html5 - Only allow one audio element to play at a time -


i have multiple audio players, each play , stop button, on 1 page. issue have when click 1 play button, , another, play on top of 1 another. can me code need stop whatever song playing when play button clicked - there never more 1 song playing @ time?? thanks! here code:

$(document).ready(function(){      $("#play-bt").click(function(){         $("#audio-player")[0].play();     })      $("#stop-bt").click(function(){         $("#audio-player")[0].pause();         $("#audio-player")[0].currenttime = 0;     }) })   $(document).ready(function(){     $("#play-bt1").click(function(){         $("#audio-player1")[0].play();     })      $("#stop-bt1").click(function(){         $("#audio-player1")[0].pause();         $("#audio-player1")[0].currenttime = 0;     }) }) 

$(document).ready(function(){       var allaudioels = $('audio');      function pauseallaudio() {        allaudioels.each(function() {           var = $(this).get(0);           a.pause();        });     }       $("#play-bt").click(function(){         pauseallaudio();         $("#audio-player")[0].play();     })      $("#stop-bt").click(function(){         $("#audio-player")[0].pause();         $("#audio-player")[0].currenttime = 0;     })      $("#play-bt1").click(function(){         pauseallaudio();         $("#audio-player1")[0].play();     })      $("#stop-bt1").click(function(){         $("#audio-player1")[0].pause();         $("#audio-player1")[0].currenttime = 0;     }) }) 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -