手机
当前位置:查字典教程网 >网页设计 >XHTML >在html中插入音频文件在浏览器中播放音频文件的兼容性问题
在html中插入音频文件在浏览器中播放音频文件的兼容性问题
摘要:下面谈谈本人在html中插入音频文件,经过我的本地测试总结的一些问题(播放mp3文件):1、问题:IE8上正常(通过mediaplayer插...

下面谈谈本人在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="http://www.jb51.netsounds/alert/1.mp3" type="audio/mp3" hidden="true" loop="false" mastersound></embed>');

}

else if(ua.match(/chrome/([d.]+)/)){

jQuery('#__alert_sound').html('<audio src="http://www.jb51.netsounds/alert/1.mp3" type="audio/mp3" autoplay=”autoplay” hidden="true"></audio>');

}

else if(ua.match(/opera.([d.]+)/)){

jQuery('#__alert_sound').html('<embed src="http://www.jb51.netsounds/alert/1.mp3" hidden="true" loop="false"><noembed><bgsounds src="http://www.jb51.netsounds/alert/1.mp3"></noembed>');

}

else if(ua.match(/version/([d.]+).*safari/)){

jQuery('#__alert_sound').html('<audio src="http://www.jb51.netsounds/alert/1.mp3" type="audio/mp3" autoplay=”autoplay” hidden="true"></audio>');

}

else {

jQuery('#__alert_sound').html('<embed src="http://www.jb51.netsounds/alert/1.mp3" type="audio/mp3" hidden="true" loop="false" mastersound></embed>');

}

【在html中插入音频文件在浏览器中播放音频文件的兼容性问题】相关文章:

input元素[type="file"]时的样式定制及浏览器兼容性问题探讨

让网站在浏览器网址前面显示小图标的方法

浅谈script在html中的摆放位置

网页排版应该考虑IE6的兼容性问题

Html注释 Html中标记文字注释的符号

html 文本框(text)不可用只读的多种实现方法

用Meta标签代码让360双核浏览器默认极速模式不是兼容模式

为何html中嵌入mp4格式视频播放不了

html 可输入下拉菜单的实现方法

网页制作中注意应用HTML标签的问题

精品推荐
分类导航