如何检测HTML5音频MP3支持? [英] How to detect HTML5 audio MP3 support?

查看:181
本文介绍了如何检测HTML5音频MP3支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在Javascript中检查HTML5音频播放是否可用.但是我该如何具体检查MP3音频播放是否可用,因为IE9和Chrome支持它,而Firefox和Opera没有.

I know how to check in Javascript if HTML5 audio playback is available. But how do I specifically check if MP3 audio playback is available, as IE9 and Chrome support it, while Firefox and Opera do not.

推荐答案

您可以检查User-Agent并查看正在使用的浏览器,也可以测试对Javascript的支持.

You could either check the User-Agent and see what browser is being used or you could test support with Javascript.

var a = document.createElement('audio');
return !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''));

我从此页面中获得了上述代码.

I got the above code from this page.

返回!!(a.canPlayType)更好,因为(某些最新版本的)Firefox不支持mp3,而a.canPlayType('audio/mpeg;')将为假

return !!(a.canPlayType) is better because (some recent versions of)Firefox not supports mp3 and a.canPlayType('audio/mpeg;') will be false

这篇关于如何检测HTML5音频MP3支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆