0

I am working on a project which is in html5. I am testing it in ipad. I have one background audio which play when page load. I made all code to play it, but it not play when it page load. If i click on play button then it play nicely.

Now what i want is to play audio automatically (autoplay). Below is my code,

$(document).ready(function() {
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'S6.mp3');
audioElement.controls = true;
audioElement.load();
audioElement.play();



audioElement.play();
$('.play').live('click',function() {
    //alert('play');                     // alert('asdsad');
    audioElement.play();
    $("#play").removeClass("play").addClass("pause");

});
$('.pause').live('click',function() {
//  alert('pause');                    // alert('4545');
    audioElement.pause();
    //$("#play").html('<a href="#" title="Play" class="play" id="play">');

    $("#play").removeClass("pause").addClass("play");


});

$('.soundhover').live('click',function() {
    audioElement.volume=0;
    $("#off").removeClass("soundhover").addClass("soundoff");
});

    $('.soundoff').live('click',function() {
    audioElement.volume=1;
    $("#off").removeClass("soundoff").addClass("soundhover");
});

});

satya
  • 11
  • 1
  • 1
  • 3