在html中插入音频文件在浏览器中播放音频文件的兼容性问题
导读:收集整理的这篇文章主要介绍了在html中插入音频文件在浏览器中播放音频文件的兼容性问题,觉得挺不错的,现在分享给大家,也给大家做个参考。 下面谈谈本人在htML中插入音频文件,经过我的本地测试总结的一些问题(播放mP3文件 : 1...
收集整理的这篇文章主要介绍了在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> ');
}
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 在html中插入音频文件在浏览器中播放音频文件的兼容性问题
本文地址: https://pptw.com/jishu/587963.html