在Internet Explorer中播放HTML音频? [英] Play HTML audio in Internet Explorer?

查看:193
本文介绍了在Internet Explorer中播放HTML音频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个html和js,我用它来播放音频:

I have this html and js which I'm using to play some audio:

HTML

<div id="audio-clips">
    <audio src="/audio/cha-ching.wav" type="audio/wav" id="audio-cha-ching">
</div>

JavaScript

JavaScript

var sfx = $("#audio-clips #audio-cha-ching")[0];
sfx.play();

这在IE 8中失败,因为它没有识别播放方法。是否有一个jQuery音频播放方法跨浏览器,使用相同的代码?我宁愿这样做,然后尝试回到某些特定于IE的解决方案(因为特定于浏览器的解决方案总是很脆弱)。

This is failing in IE 8, due to it not recognising the "play" method. Is there a jQuery audio-playing method which works cross-browser, with the same code? I'd rather do that then try to fall back to some IE-specific solution (as browser-specific solutions are always brittle).

推荐答案

我强烈建议使用howler.js播放音频文件。它在浏览器和设备之间具有出色的兼容性它在可用时使用HTML5音频,并在必要时回退到旧技术。

I would strongly recommend using howler.js for playing audio files. It has great compatibility across browsers and devices. It uses HTML5 audio when available, and falls back to older technologies when necessary.

这篇关于在Internet Explorer中播放HTML音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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