做html5音频标签吃掉了资源 [英] do html5 audio tags eat up resources

查看:120
本文介绍了做html5音频标签吃掉了资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有页面,当用户点击某些内容时,我需要播放几十个小音频文件。反应非常重要。

I have pages where i need to play dozens of small audio file when the user clicks on things. Responsiveness is very important.

我正在考虑为每个文件使用一个,并预加载音频文件。这是一种合理的方法吗?

I'm thinking of using one for each file, and preloading the audio files. Is this the a reasonible approach?

谢谢。

推荐答案

这是合理的,也许是正确的解决方案。我最近写了一个演示应用程序( http://www.soundscribe.com ),大量使用个人(和HTML5中的同步音频剪辑。 IE9和FF3 / 4处理得很好。 Chrome有一些问题似乎与同步播放特别相关(可能不适用于您的应用)。我遇到的最大块是IE9,它似乎对可以同时存在的音频对象的数量有一个神秘的限制。最大值约为40,之后IE9将无声下载文件。 FF和Chrome都试图支持无限数量。

It's reasonable, and probably the correct solution. I recently wrote a demo application (http://www.soundscribe.com) that makes heavy use of individual (and simultaneous) audio clips in HTML5. IE9 and FF3/4 handle it well. Chrome has some issues that seem to be specifically related to simultaneous playback (which probably won't apply to your app). The biggest block I hit was in IE9, which seems to have a mysterious limit on the number of audio objects that can exist at once. The max is about 40, after which IE9 will silently fail to download the file. FF and Chrome both try to support an unlimited number.

将所有音频放在一个文件中并更改偏移量的替代方法对于几个原因。编码要复杂得多,你需要跟上额外的元数据(剪辑从哪里开始,有多长时间),并且浏览器之间的工作可能略有不同。最糟糕的是,实际上没有办法知道剪辑何时满载。您只能判断剪辑何时可以播放,这是由浏览器根据音频文件的大小和当前下载速率确定的。这意味着即使在浏览器报告音频剪辑准备就绪后,您也可能无法在接近结尾处播放剪辑。

The alternative approach of putting all the audio in a single file and changing the offset to play is a bad choice for several reasons. It's much more complicated to code, you need to keep up with additional metadata (where does the clip start, how long is it), and it's likely to work slightly different between browsers. And the worst part, there's really no way to know when your clip is fully loaded. You can only tell when the clip "can play through", which is determined by the browser based on the size of the audio file and the current download rate. This means that even after the browser reports the audio clip is ready, you may not be able to play a clip somewhere near the end.

这篇关于做html5音频标签吃掉了资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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