使用Modernizr检测html5音频支持 [英] Detecting html5 audio support with Modernizr

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

问题描述

是否可以通过Modernizr检测浏览器是否支持Html5音频?如果是的话,这是如何做到的?如果不是有任何解决方法吗? Google上很少有资源解释这一点,所以任何帮助都不会感激。

是的,通过modernizr.audio。它支持多种音频格式(目前ogg,mp3,m4a和wmv)。示例:

  var audio = new Audio(); 
audio.src = Modernizr.audio.ogg? 'background.ogg':
Modernizr.audio.mp3? 'background.mp3':
'background.m4a';
audio.play();

文档


Is it possible to detect if the browser has Html5 Audio support through Modernizr? If so how is this done? If not are there any work around's? There's few resources on Google explaining this, so any help would be appreciated.

解决方案

Yes, through modernizr.audio. It supports a number of audio formats (currently ogg, mp3, m4a & wmv). Example:

var audio = new Audio();
audio.src = Modernizr.audio.ogg ? 'background.ogg' :
            Modernizr.audio.mp3 ? 'background.mp3' :
                                  'background.m4a';
audio.play();

More info in the documentation.

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

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