我怎么能强制HTML5音频元素来缓冲整首歌曲? [英] How can I force an HTML5 audio element to buffer an entire song?

查看:254
本文介绍了我怎么能强制HTML5音频元素来缓冲整首歌曲?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发将流用户的音频文件,这样他们可以通过使用HTML5音频对象的Web浏览器访问它们本地服务器。由于这些文件是在用户的计算机上,我希望它们被加载时,文件被完全缓冲,但是对于某些大文件,歌曲获得的方式缓冲部分,然后停止,并恢复后缓冲一段时间。

I'm developing a local server that will stream a user's audio files so they can access them via web browsers using the HTML5 audio object. Since these files are on the user's computer, I expect the files to be buffered completely when they are loaded, but for certain large files, the songs get buffered part of the way, then stop, and resume buffering some time later.

我的问题是:我怎么能强制音频对象在一次缓冲整首歌曲?我能做到这一点从JavaScript,我必须设置音频对象的属性,或者是有什么我可以做什么?

My question is: how can I force the audio object to buffer the entire song at once? Can I do this from javascript, do I have to set an attribute on the audio object, or is there anything else I can do?

推荐答案

我发现了这个问题的解决:

The solution I found was this:

function load() {
    a.play();
    setTimeout("a.pause()", 10);
}

播放该文件,并暂停10毫秒之后,那么浏览器就会缓冲整个歌曲。

Play the file and pause it 10ms later, then the browser will buffer the entire song.

这篇关于我怎么能强制HTML5音频元素来缓冲整首歌曲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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