0

I've got a simple toggle function for music that is playing when a page loads. The user can press the "music off" button, and it clears out the div. If they press "music on" to bring the music back, i get the "your browser doesn't support audio" message. Which is odd... considering it was just playing???

Here's the html:

<div id="music">

<audio autoplay loop> 
   <source src="http://site.com/music/0132.ogg" type="audio/ogg" />
   <source src="http://site.com/music/0132.mp3" type="audio/mpeg" />
    Your browser does not support the audio element.
</audio>

</div>
<a href="#" id="music_control" class="">MUSIC OFF</a>

and here's the javascript:

$(document).ready(function() {

    var playing = true;

    $("#music_control").click(function(){

        if (playing == false) {
        playing = true;

          $('#music').html("  <source src='http://site.com/music/0132.ogg' type='audio/ogg' /><source src='http://site.com/music/0132.mp3' type='audio/mpeg' />Your browser does not support the audio element. ");
          $("#music_control").text("MUSIC OFF"); 

        } else if (playing == true) {
          playing = false;

          $('#music').html("<!-- music -->");
          $("#music_control").text("MUSIC ON"); 

        } 
      }); 
});
2
Contributors
1
Reply
5
Views
4 Years
Discussion Span
Last Post by pritaeas
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.