javascript - IE 11 not supporting audio playing? -


i have checked w3schools.com , createelement(), setattribute() , play() meant supported ie 11? below js code works fine in other modern browsers. thoughts?

 <!doctype html>  <html>  <head>  <meta charset="utf-8">   <script type="text/javascript">    var amusic = document.createelement('audio');    amusic.setattribute('src', 'sing.wav');    amusic.play();    </script>   </head>   <body>   </body>  </html> 

live example - https://jsfiddle.net/40x303ka/

your code specifies wav file audio file. seen on w3schools website, internet explorer not support wav files.

for maximum cross-browser support, reccomend either using mp3 file, or better, specifying files based on browser compatibility so:

var amusic = document.createelement('audio'); var source= document.createelement('source'); if (audio.canplaytype('audio/mpeg;')) {     source.type= 'audio/mpeg';     source.src= 'audio/sing.mp3'; } else {     source.type= 'audio/ogg';     source.src= 'audio/sing.ogg'; } amusic.appendchild(source); 

if still want use wav file, check out link: http://www.phon.ucl.ac.uk/home/mark/audio/play5.htm

it uses non-standard bgsound tag used ie play wav files.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -