• 在html中插入音频文件


     1、<embed type="audio/mp3" src="" autostart=true  loop=false></embed>
        问题:IE8上正常(通过media player插件来播放)但在IE6和IE7上不会播放
              Firefox上要安装QuickTime插件才能播放
              Chrome通过将其转化成html5上的<vidio>标签播放,能播放但会使整个屏幕蓝屏
              Opera不会自动播放
     2、<embed type="audio/midi" src="" autostart=true loop=false></embed>
        问题:IE6,IE7上不会正常播放,IE8正常
              Firefox上正常
              Chrome上要求肮脏QuickTime插件才能正常播放
              Opera不会自动播放
     3、<object data="" />
        问题:在IE6,7上不能播放,IE8会弹出“非正常使用的Articx”等字样的提示
              Firefox上正常
              Chrome上正常
              Opera不支持
     4、<audio src="" type="audio/mp3" />
        问题:html5标签 仅Chrome支持
     5、<audio autoplay>
           <source src="" type="audio/mp3" />
           <embed src="" type="audio/mp3"/>
        </audio>
        问题:IE6,IE7不支持,其余浏览器均支持,Opera不能自动播放
      6、<embed src=""><noembed><bgsound src=""></noembed>
        问题:IE6,IE7均不支持,其余浏览器均支持,Opera不能自动播放

      综合以上本人采取了一下方式(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>');
                            }    

     标注:其实本人觉得应该可以通过flash player来播放,这样各个浏览器应该都能兼容,但可惜本人苦苦寻求也没有找到一种正确的用flash player来播放的方法。希望有哪位高手有解决之道的话给小弟留言,小弟现在这里谢谢啦!!

  • 相关阅读:
    Java异常处理和设计
    一次qps测试实践
    Alternate Task UVA
    Just Another Problem UVA
    Lattice Point or Not UVA
    Play with Floor and Ceil UVA
    Exploring Pyramids UVALive
    Cheerleaders UVA
    Triangle Counting UVA
    Square Numbers UVA
  • 原文地址:https://www.cnblogs.com/zmeieasyjob/p/4223880.html
Copyright © 2020-2023  润新知