简体   繁体   English

SoundJS:混合html和网络音频

[英]SoundJS: mix html and web audio

I want to play buffered audio in my game for long music files (sort of streaming). 我想在游戏中播放缓冲的音频,以获取长音乐文件(某种流)。 It seems I have to use html audio: Buffered audio in SoundJS 看来我必须使用html音频: SoundJS中的缓冲音频

However, I still want to use webaudio for sound effects (to avoid delay on mobile browsers, for example). 但是,我仍然想将we​​baudio用作声音效果(例如,避免在移动浏览器上出现延迟)。

Is this doable? 这可行吗? Can I use html audio for some sounds and web audio for other sounds in the same page, or I'll have to manually create some html audio tags for my music files? 我可以在同一页面中将html音频用于某些声音,将网络音频用于其他声音,还是必须为音乐文件手动创建一些html音频标签?

You actually can stream into the web audio api, it adds a fair amount of complexity though. 实际上,您可以流式传输到Web音频api,但是它增加了相当多的复杂性。 You will have to manually append audio data fragments to the buffer you are playing as they come in and move loading and decoding into a web worker so you don't block the main thread. 您必须将音频数据片段手动添加到正在播放的缓冲区中,然后再将其加载和解码到Web Worker中,以免阻塞主线程。 Because web audio isn't available in web workers you have to use a third party decoding library. 由于网络工作者无法使用网络音频,因此您必须使用第三方解码库。 I switched to Aurora in a web worker for loading and decoding audio in an app, it downloads and decodes the audio in chunks and doesn't block main thread. 我切换到网络工作者中的Aurora ,用于在应用程序中加载和解码音频,它以块的形式下载和解码音频,并且不会阻塞主线程。 Also decode audio data from the web api uses up all your cpu in Firefox, up to 95% on my machine which is fairly fast. 此外,从Web api解码音频数据还会用完Firefox中的所有CPU,在我的计算机上高达95%,这是相当快的。 Ontop of that it allowed me to load far more audio assets without crashing the browser tab, 100+ 20mb wav files where ad on the main thread the browser tab would crash at a little over 40. 最重要的是,它使我可以加载更多的音频资产而不会崩溃浏览器选项卡,100 + 20mb的wav文件,其中浏览器选项卡的主线程上的广告将崩溃超过40点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM