Including more Audios in a Function

Asked

Viewed 35 times

-3

o Daniel, last week suggested an audio Function, which met perfectly what I wanted. It turns out I need to insert more audios. Dai includes a #audio3 and I made the changes in Function. The result is not expected, IE, I’m playing in #audio3, the #audio2 continues... Sorry, I tried to change Function, but I’m not succeeding.

<!--function do audio -->
	  <script>
			$(function(){

		  $("#audio1").on('play', function(){
			var pe = $("#audio2").get(0);
			var pe = $("#audio3").get(0);  

			if(pe.paused == false)
			  pe.pause();
		  });

		  $("#audio2").on('play', function(){
			var pe = $("#audio1").get(0);
			var pe = $("#audio3").get(0);  

			if(pe.paused == false)
			  pe.pause();
		  });
				
		  $("#audio3").on('play', function(){
			var pe = $("#audio1").get(0);
			var pe = $("#audio2").get(0);  

			if(pe.paused == false)
			  pe.pause();
		  });		

		});
		  
		  
        
	</script>

1 answer

0

Resolvei by changing Function like this:

 <!--function do audio -->
  <script>
        $(function(){

      $("#audio1").on('play', function(){
        var pe = $("#audio2").get(0);

        if(pe.paused == false)
          pe.pause();
      });

      $("#audio1").on('play', function(){
        var pe = $("#audio3").get(0);  

        if(pe.paused == false)
          pe.pause();
      });

      $("#audio2").on('play', function(){
        var pe = $("#audio1").get(0);

        if(pe.paused == false)
          pe.pause();
      });

      $("#audio2").on('play', function(){
        var pe = $("#audio3").get(0);  

        if(pe.paused == false)
          pe.pause();
      });       


      $("#audio3").on('play', function(){
        var pe = $("#audio1").get(0);

        if(pe.paused == false)
          pe.pause();
      });       

      $("#audio3").on('play', function(){
        var pe = $("#audio2").get(0);  

        if(pe.paused == false)
          pe.pause();
      });               


    });



</script>

<!--Fim function audio-->  

Result was as expected. Does not allow to run twice an audio, only one at a time.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.