Categories
Mastering Development

Stop playing audio when other is clicked and no repeat event when multi click

This is my code. I have 2 buttons one is linked to #streama and the other is linked to streamb
I have 2 problems

  1. When I click any button twice it plays the audio twice (3clicks = 3time being played at the same time … and so on)
  2. When I click any button the other audio must stops so it allow the new clicked button to play alone

    (function( $ ) {
    $( “#streama” ).on( “click”, function( event ){
    var hassen = new Audio(‘http://mywebsite:8000/streama‘);
    hassen.play();
    event.preventDefault();
    });
    })( jQuery );

    (function( $ ) {
    $( “#streamb” ).on( “click”, function( event ){
    var hassen = new Audio(‘http://mywebsite:8000/streamb’);
    hassen.play();
    event.preventDefault();
    });
    })( jQuery );

Leave a Reply

Your email address will not be published. Required fields are marked *