如何检测HTML5音频MP3支持 [英] How to detect HTML5 audio MP3 support
问题描述
如果HTML5音频播放可用,我知道如何检查Javascript。但是,我该如何专门检查MP3音频播放是否可用,因为IE9和Chrome支持它,而Firefox和Opera则不支持。
您可以检查用户代理并查看正在使用的浏览器,或者您可以使用Javascript测试支持。
var a = document.createElement('audio');
return !!(a.canPlayType&& a.canPlayType('audio / mpeg;')。replace(/ no /,''));
我从 ('audio / mpeg;')将为false 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. You could either check the User-Agent and see what browser is being used or you could test support with Javascript. I got the above code from this page. 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屋!var a = document.createElement('audio');
return !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''));