下面谈谈html中插入音频文件,经过我的本地测试总结的一些问题(播放mp3文件):

3

<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95">
            <param name="AutoStart" value="1" />
            <param name="Src" value="images/hua/start_20160309.mp3" />
            <param name="LOOP" value="true">
     </object>

     问题:在IE7+上能播放,IE8会弹出“非正常使用的Articx”等字样的提示;
             Chrome、Opera、Firefox、UC上不能播放;

4、

<audio autoplay="autoplay" loop="loop" preload="auto">
                <source src="images/hua/start_20160309.mp3" loop="loop" type="audio/mpeg">
                <source src="images/hua/start_20160309.ogg" loop="loop" type="audio/mpeg">
                <source src="images/hua/start_20160309.wav" loop="loop" type="audio/mpeg">
     </audio>

    问题:html5标签 经过测试Chrome、Opera、Firefox、IE9+、UC正常
 
  综合以上本人采取了一下方式(jquery下执行):

if(navigator.userAgent.indexOf("Chrome") > -1){


     如果是Chrome:

<audio src="" type="audio/mp3" autoplay=”autoplay” hidden="true"></audio>
    }else if(navigator.userAgent.indexOf("Firefox")!=-1){


     如果是Firefox:

<embed src="" type="audio/mp3" hidden="true" loop="false" mastersound></embed>
    }else if(navigator.appName.indexOf("Microsoft Internet Explorer")!=-1 && document.all){


      如果是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){


       如果是Oprea:

<embed src="" type="audio/mpeg"   loop="false"></embed>
    }else{
       <embed src="" type="audio/mp3" hidden="true" loop="false" mastersound></embed>
    }


  或

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>');
                        }