Reputation: 343
I have checked w3schools.com 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.net/40x303ka/
Upvotes: 1
Views: 8065
Reputation: 31
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 completed, you need to restart the computer and then the feature gets enabled.
Upvotes: 0
Reputation: 91
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 reccomend either using an MP3 file, or even better, specifying files based on browser compatibility 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.
Upvotes: 6