Search code examples
phpjquerysafarihtml5-audio

.play() function not working on safari browser with audio tag


I am building a website http://directhearingtest.com/ and it's working fine and playing audio files on click using jquery but in safari browser IPad it's giving the following error

TypeError: 'undefined' is not a function (evaluating '$('audio#audio2')[0].play()')

I have tried many solutions but not solving it. Here is the HTML script

<audio id="audio2" > 
    <source src="tunes/500 HZ/20.wav" type="audio/mpeg" >
</audio>

<a  id="start_sample" class="text-white font-weight-bold pl-3 pr-3 pt-2 pb-2 p " style="cursor: 
  pointer; background-color:#2e7ed5; border-radius: 25px; border: 6px solid; font-family: sans-serif; 
  ">Play sample tones</a>

Here is the Jquery Script

$(document).ready(function(){
  $('#start_sample').click(function(){
    $('audio#audio2')[0].play();
 });
});

Please help out me.


Solution

  • try a different format. Wav files may not be supported.