标题 | 在html中插入音频文件在浏览器中播放音频文件的兼容性问题 |
范文 | 下面谈谈本人在html中插入音频文件,经过我的本地测试总结的一些问题(播放mp3文件): 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>'); } |
随便看 |
|
在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。