Rather than storing the id
of the current playing audio
element, you can simplify your logic by pausing them as a group when playing a new one:
$(function () {
$(".playback").click(function (e) {
e.preventDefault();
var $playback = $(this);
$('audio').not(this).each(function() { $(this)[0].pause(); });
var audio = $(this).next('audio')[0];
if (audio.paused) {
audio.play()
$playback.html('<i class="fa fa-pause"></i> Stop');
}
else {
audio.pause();
$playback.html('<i class="fa fa-play"></i> Play');
}
});
});
Post a Comment for "Multiple Instance Audio Play Using Jquery /javascript"