如何在浏览器中零间隙循环播放 mp3?
我正在尝试制作一个吉他练习网站,一个关键功能是循环播放非常短的 mp3 文件(几秒钟长),其间的间隙绝对为零。例如,它可以是 4 小节长的和弦进行,我想让用户无缝地循环播放它。
我尝试使用带有 loop
属性的 HTML5 标签。谷歌浏览器在循环之间提供了一个很小的间隙,但对于我的目的来说已经足够大了,完全无法接受。我没有测试过其他浏览器,但我相信它不会工作。
一种可能的解决方法是使用 ffmpeg 来重复传输与 mp3 相同的音频。然而,这会消耗大量带宽。
对于我自己,我使用 Audacity 进行无间隙循环,但不幸的是 Audacity 没有网络版本。
那么,您知道如何在浏览器中零间隙地循环播放 mp3 吗?我更喜欢非 Flash 解决方案,但如果其他方法都不起作用,我将使用 Flash。
编辑: 感谢您的所有建议。事实证明,Flash 工作得很好。我在 http://vmlucid.lcm.hk/~netvope 制作了一个玩具演示/audio/flash.html。令我惊讶的是(我以前只将 Flash 与资源占用和浏览器崩溃联系起来),Flash 和 ActionScript 设计得相当好并且易于使用。我的第一个 Flash 项目只花了 3 个小时:)
I'm trying to make a guitar practice website, and a critical functionality is to loop over very short mp3 files (a few seconds long), with absolutely zero gap in between. For example, it could a 4-measures-long chord progression, and I want to allow the user to loop over it seamlessly.
I tried using the HTML5 <audio>
tag with the loop
attribute. Google Chrome gives a small gap between the loops, but big enough to be totally unacceptable for my purpose. I haven't tested the other browsers, but I believe it won't work.
A possible workaround is to use ffmpeg
to stream repetitions the same audio as an mp3. However, this costs a lot of bandwidth.
For myself I use Audacity to loop without gaps, but unfortunately Audacity doesn't have a web version.
So, do you have any ideas how I may loop over an mp3 in a browser with zero gap? I prefer non-Flash solutions, but if nothing else works I'll use Flash.
Edit:
Thank you for all your suggestions. Flash turns out to work decently. I've made a toy demo at http://vmlucid.lcm.hk/~netvope/audio/flash.html. To my surprise (I use to associate Flash with resource hog and browser crashes only), Flash and ActionScript are rather well designed and easy to use. It took me only 3 hours on my first Flash project :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请查看此页面。使用 Google Chrome 7 听了一段时间,我发现方法 1 效果不错,而方法 3 给出了最好的结果,尽管它有点破解。最终,所有浏览器的工作方式都不同,特别是 HTML5 尚未最终确定。如果可能的话,您应该选择 Flash 版本,我认为这会给您带来最佳的循环效果。
Have a look at this page. Listening for a while using Google Chrome 7, I found Method 1 works decently, while Method 3 gives the best results, though it's a bit of a hack. Ultimately, all browsers work differently, especially since HTML5 isn't finalized yet. If possible, you should opt for a Flash version, which I would think would give you the best loop.
在 flash AS3 中,您可以使用 computeSpectrum() 并在需要时将其提供给您的 Sound 对象 (SampleDataEvent 被触发)。
in flash AS3 you can extract sound data with computeSpectrum() and give it to your Sound object exactly when it's needed (SampleDataEvent is fired).
我不确定这效果如何,但如果你知道你的循环持续了 800 毫秒 - 你可以让浏览器每 800 毫秒调用一次 play 方法......但它仍然不能保证是完美的。我不认为浏览器本身能够提供可靠的音频循环。
有传言说,最好的方法是以最无缝的方式实现这一点,以使用多个音频标签并在它们之间交替。
I am not sure how well this will work, but if you knew your loop lasted 800 milliseconds - you could have the browser call the play method every 800ms... it still wouldn't be guaranteed to be perfect though. I don't think the browser is natively capable of delivering reliable audio looping at this point.
Rumor has it the best way to do pull this off in the most gapless fashion to use to multiple audio tags and alternate between them.
或者查看此实用程序:http://www.compuphase.com/mp3/mp3loops.htm 当音乐必须不间断地循环时,我成功地将它用于我的 Flash 项目,并且 99% 的时间都有效。它以 WAV 作为输入。
基本上它是一种 LAME mp3 编码器的前端,它使用这样的设置来防止出现间隙。它不适用于非常短的音效(我相信不到 0.5 秒)。
之后你所要做的就是使用:
它会循环一千次。
Or check out this utility: http://www.compuphase.com/mp3/mp3loops.htm I used it successfully for my flash projects when music had to be looped without gaps, and 99% of the time it worked. It takes WAV as an input.
Basically it is a kind of front-end for LAME mp3 encoder, which uses such settings as to prevent the gaps appearing. It won't work on very short sound effects (less than 0.5 second I believe).
Afterward all you have to do is use:
and it will loop one thousand times.