我目前正在使用node-lame编码原始PCM输入流,并且在Node.JS中有以下代码可以成功输出二进制MP3块:
I'm currently using node-lame to encode a raw PCM input stream, and I have the following code in Node.JS that successfully outputs binary MP3 chunks:
server.on('request', (req, res) => { encoded.pipe(res); });我尝试使用以下代码在前端界面中请求此代码:
I try to request this code inside of my front-end interface with code like the following:
var audio = new Audio('localhost:8000/a.mp3'); // the above audio.play();但是,由于音频源是一个连续的输入流,因此内容不断下载而没有结束:
However, as the audio source is a continuous input stream, the content just keeps getting downloaded without end:
相反,我希望能够在下载块时播放它们.
Instead, I want to be able to play the chunks as they are downloaded.
我可以在VLC或Quicktime Player之类的应用程序中访问localhost:8000/a.mp3,并且音频传输正常.我只是对如何最好地在网络上做到这一点感到困惑.
I can access localhost:8000/a.mp3 in an application like VLC or Quicktime Player, and the audio delivery works fine; I'm just stumped as to how to best do this on the web.
谢谢.
推荐答案此代码对我们有效:
<audio id="music" preload="all"> <source src="localhost:8000/a.mp3"> </audio> <script> let music = document.getElementById('music'); music.play(); </script>更多推荐
播放JavaScript中的流音频
发布评论