最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - IE 11 not supporting audio playing? - Stack Overflow

programmeradmin6浏览0评论

I have checked w3schools and createElement(), setAttribute() and play() are all meant to be supported by IE 11? The 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 - /

I have checked w3schools. and createElement(), setAttribute() and play() are all meant to be supported by IE 11? The 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/40x303ka/

Share Improve this question edited Aug 16, 2015 at 19:14 Stone asked Aug 16, 2015 at 18:44 StoneStone 3431 gold badge5 silver badges12 bronze badges 2
  • Are you hosting this on a server or your local filesystem? – code4coffee Commented Aug 16, 2015 at 18:48
  • @code4coffe I am using XAMPP via localhost, I have tried entering the full URL without success and also using ngrok to see if that changes anything but that does not help either. – Stone Commented Aug 16, 2015 at 18:50
Add a ment  | 

2 Answers 2

Reset to default 6

Your code specifies a WAV file as the audio file. As seen on the W3Schools website, Internet Explorer does not support WAV files.

For maximum cross-browser support, I would recend either using an MP3 file, or even better, specifying files based on browser patibility like 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 you still want to use a WAV file, check out this link: http://www.phon.ucl.ac.uk/home/mark/audio/play5.htm

It uses the non-standard bgsound tag that is used only by IE to play WAV files.

I was working in a windows server and I had the same problem playing MP3 audios in internet explorer.

The only solution I found was installing the "Desktop Experience Feature" in my server.

Start -> Search for "Server manager" -> Features -> Add features -> Select "Desktop experience" -> Next and Install

Once installation is pleted, you need to restart the puter and then the feature gets enabled.

发布评论

评论列表(0)

  1. 暂无评论