Source: http://blog.sina.com.cn/s/blog_96ae64bd0100zk9r.html below to talk about myself inserting audio files in HTML, after my local test summarizes some of the issues (play MP3 file):
1, <embed type= "Audio/mp3" src= "" Autostart=true loop=false></embed>
Problem: Normal on IE8 (play via Media Player plugin) but not on IE6 and IE7
Install QuickTime plugin on Firefox to play
Chrome converts it to a <vidio> tab on HTML5, which plays but makes the entire screen blue screen
Opera does not play automatically
2, <embed type= "Audio/midi" src= "" Autostart=true loop=false></embed>
Problem: Ie6,ie7 will not play properly, IE8 normal
Normal on Firefox
Dirty QuickTime plugin required on chrome to play normally
Opera does not play automatically
3, <object data= ""/>
Problem: Cannot play on ie6,7, IE8 will pop up "abnormal use of articx" and other words hint
Normal on Firefox
Normal on Chrome
Opera does not support
4, <audio src= "" type= "Audio/mp3"/>
Issue: HTML5 tag only chrome support
5, <audio autoplay>
<source src= "" type= "Audio/mp3"/>
<embed src= "" type= "Audio/mp3"/>
</audio>
Problem: Ie6,ie7 not supported, other browsers are supported, opera cannot play automatically
6, <embed src= "" ><noembed><bgsound src= "" ></noembed>
Problem: Ie6,ie7 are not supported, other browsers are supported, opera cannot play automatically
Integrated above I took a look at the way (jquery under execution):
if (Navigator.userAgent.indexOf ("Chrome") >-1) {
If it's chrome:
<audio src= "" type= "Audio/mp3" autoplay= "AutoPlay" hidden= "true" ></audio>
}else if (navigator.userAgent.indexOf ("Firefox")!=-1) {
If it's Firefox:
<embed src= "" type= "Audio/mp3" hidden= "true" loop= "false" mastersound></embed>
}else if (navigator.appName.indexOf ("Microsoft Internet Explorer")!=-1 && document.all) {
If it is IE (6,7,8):
<object classid= "Clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" ><param name= "AutoStart" value= "1"/>< param name= "SRC" value= ""/></object>
}else if (navigator.appName.indexOf ("Opera")!=-1) {
If it is Oprea:
<embed src= "" type= "Audio/mpeg" loop= "false" ></embed>
}else{
<embed src= "" type= "Audio/mp3" hidden= "true" loop= "false" mastersound></embed>
}
Or
var ua = Navigator.userAgent.toLowerCase ();
if (Ua.match (/msie ([\d.] +)/)){
JQuery (' #__alert_sound '). html (' <object classid= "clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" ><param name = "AutoStart" value= "1"/><param name= "SRC" value= "/sounds/alert/1.mp3"/></object> ");
}
else if (Ua.match (/firefox\/([\d.] +)/)){
JQuery (' #__alert_sound '). html (' <embed src= "/sounds/alert/1.mp3" type= "Audio/mp3" hidden= "true" loop= "false" Mastersound></embed> ');
}
else if (Ua.match (/chrome\/([\d.] +)/)){
JQuery (' #__alert_sound '). html (' <audio src= "/sounds/alert/1.mp3" type= "Audio/mp3" autoplay= "AutoPlay" hidden= " True "></audio>");
}
else if (Ua.match (/opera) ( [\d.] +)/)){
JQuery (' #__alert_sound '). html (' <embed src= "/sounds/alert/1.mp3" hidden= "true" loop= "false" ><noembed> <bgsounds src= "/sounds/alert/1.mp3" ></noembed> ");
}
else if (Ua.match (/version\/([\d.] +). *safari/)) {
JQuery (' #__alert_sound '). html (' <audio src= "/sounds/alert/1.mp3" type= "Audio/mp3" autoplay= "AutoPlay" hidden= " True "></audio>");
}
else {
JQuery (' #__alert_sound '). html (' <embed src= "/sounds/alert/1.mp3" type= "Audio/mp3" hidden= "true" loop= "false" Mastersound></embed> ');
}
Compatibility issues with audio files playing in the browser