简体   繁体   中英

How to support HTML5 audio tag in older versions of Internet Explorer?

I am trying to play a simple audio file using audio tag with autoplay set to true . It works fine in chrome,firefox but having no luck in Internet Explorer older versions. How to fix this ?

Code I am trying:

<html>
<head>
</head>
<body>
<div id="sound_notification"></div>
<button id="playButton" onclick="messageNotification()">Play</button>
<script>
//TODO sound notification for incoming message

function messageNotification()
{
    console.log("inside notification handler");
    var filename="sound/notify";
    document.getElementById("sound_notification").innerHTML='<audio autoplay="autoplay"><source src="' + filename + '.mp3" type="audio/mpeg" /><source src="' + filename + '.ogg" type="audio/ogg" /><embed hidden="true" autostart="true" loop="false" src="' + filename +'.mp3" /></audio>';
}
</script>
</body>
</html>

I know HTML5 audio is not supported below IE9. I don't want the flash fall back as the user might not have flash player installed. What approach would you follow in this scenerio ?

I have found the <bgsound> tag which is only supported by IE. It served my purpose.

For supporting IE:

<html>
<head>
</head>
<body>
<!-- this tag is only supported by IE -->
<bgsound id="notification">
<button id="playButton" onclick="messageNotification()">Play</button>
<script>
//TODO sound notification for incoming message

function messageNotification()
{
    document.getElementById("notification").src="sound/notify.mp3";
}
</script>
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM