简体   繁体   English

如何使用 Javascript 将 append 多个音频文件转换为当前正在播放的音频?

[英]How to append multiple audio files to a currently playing audio using Javascript?

I have a program that plays songs from the server.我有一个从服务器播放歌曲的程序。 To make it more efficient i split the audio file on server into segments and the send them to the client using Ajax as base64 encoded.为了提高效率,我将服务器上的音频文件分成多个片段,然后使用 Ajax 将它们发送到客户端,编码为 base64。 The HTML5 native audio player plays the base64 audio segment but when playing the next audio segment, it pauses a little and then plays. HTML5 原生音频播放器播放 base64 音频片段,但在播放下一个音频片段时,它会暂停一点然后播放。 The retrieved segments are stored in IndexedDB for quick access but still it causes a pause in the playback.检索到的片段存储在 IndexedDB 中以便快速访问,但它仍然会导致播放暂停。 How to make the program more efficient as well as fix the audio pause happening between switching segments.如何使程序更高效以及修复切换段之间发生的音频暂停。

Is there any other way of appending audio file to a currently playing audio source without any pause using Javascript?是否有任何其他方法可以使用 Javascript 将音频文件附加到当前正在播放的音频源中而不会有任何暂停?

The Media Source Extensions API can do that, but note that you are just reinventing Range requests and caching, which are exactly what browsers already do for fetching media, but they do it better since they don't add the overhead of base64 on it. 媒体源扩展 API可以做到这一点,但请注意,您只是在重新发明Range 请求和缓存,这正是浏览器已经为获取媒体所做的,但它们做得更好,因为它们没有增加 base64 的开销。

So the "other way" is to configure your server to accept Range requests, to serve your file the most basically as possible in a single file, and to let the browser do its job.因此,“另一种方式”是配置您的服务器以接受 Range 请求,在单个文件中尽可能基本地为您的文件提供服务,并让浏览器完成其工作。

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

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