Splitting an HTML5 Audio Object into Multiple Audio Objects

情到浓时终转凉″ 提交于 2019-12-13 00:09:11

问题


Assuming that I've merged several audio files into a single audio file (thus using only a single HTTP request), can I split them up into several HTML5 audio objects on the client side with JavaScript and, if so, how? Also, if it is possible, would this have any advantages over multiple requests?


回答1:


https://developer.mozilla.org/en-US/docs/Using_HTML5_audio_and_video hints that you can do this under "Specifying playback range".

When specifying the uri you can add a #start,stop to specify the start end end time of the clip.

I have not tried this and so I don't know how this will affect buffering (i.e. will this cause the multiple requests you tried to avoid from the start or will the source be requested only once and then buffered?) but it might be worth playing around with




回答2:


So far, this is what I've found out...HTML5 Audio isn't built for that. Numerous other problems arise with Safari too (see this question and its answers) However, the Web Audio API seems like it might do the trick. While it's not fully supported yet, there are polyfills on github and support for the API is quickly becoming a reality. Games have already been made that utilize this API (see Field Runners)

I've also found some nice tutorials on how to use it - primarily at creativejs and html5rocks.

Lastly, I've found an excellent example of the API in use. (The sound in the example is very quiet, though. You might need to turn up your volume to hear it)



来源:https://stackoverflow.com/questions/11708317/splitting-an-html5-audio-object-into-multiple-audio-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!