在Firefox中检测不带navigator.userAgent的Shoutcast ICY MP3支持



Mozilla Firefox的当前版本是23.0.1,此版本不支持从不同于80的TCP端口播放MP3 shoutcast流(最常见的是8000用于shoutcast 1.9.8)。

当HTML5音频中不支持MP3时,我使用Flash,检测方法是:

try{
    var a = document.createElement('audio');
    r = !!(a.canPlayType && !!a.canPlayType("audio/mpeg; codecs=mp3").replace(/^no$/,''))
}catch(e){
    r = false;
}

Firefox中对Mp3 Shotcast流的支持将在版本24中添加。

a.canPlayType("audio/mpeg;codecs=mp3")=可能在Chrome和Firefox中,Chrome确实支持,Firefox不支持,因此当前要检测的代码不适用于Firefox。

当前支持IE 6的jQuery版本是1.10.2,此版本没有.brower

我认为"程式化"的方式是测试功能,而不是查询浏览器/版本,尽管在这里我很难不违反这个"原则"。

在Firefox中没有navigator.userAgent的情况下,检测MP3 ICY支持的"风格化"方法是什么?

没有复杂的方法来检测它。好消息是最后一个稳定的Firefox 24.0支持用HTML5音频在MP3中播放Shotcast流。检测我写的支持的最佳方法:

function icy(){
    try{
        if(!navigator.userAgent.match(/Trident/7./) && $.browser.mozilla && $.browser.version < 24)
            return false;//https://bugzilla.mozilla.org/show_bug.cgi?id=869725
        var a = document.createElement('audio');
        r = !!(a.canPlayType && !!a.canPlayType("audio/mpeg; codecs=mp3").replace(/^no$/,''))
    }catch(e){
        r = false;
    }
    return r;
}

如果您使用最新的jQuery 1.10.2,则需要包含jQuery Migrate插件才能使用$.brower

最新更新