【发布时间】:2017-01-29 12:34:36
【问题描述】:
我正在使用 http 流式传输音频。我正在使用以下代码加载音频。
var audio = new Audio("http://example.com/get/stream/1/wav");
function seek(time){
audio.currentTime = time;
}
浏览器可以播放音频格式。
我正在运行一个 nodejs express 服务器来提供音频文件。下面是处理流的代码的简化版本。
app.get("/get/stream/:id/:format", function(req, res){
//Here was some code to verify the request, this code doesn't affect this question so I left it out
var stat = fs.statSync(__dirname+"/path/to/file/here.wav");
res.header("Content-Type", "audio/wav");
res.header("Content-Length", stat.size);
var readStream = fs.createReadStream(__dirname+"/path/to/file/here.wav");
readStream.pipe(res);
});
如果我加载一个普通的音频文件(不使用 http 流的那个),seek 功能将正常工作,但如果我使用一个确实使用 http 流的音频文件,歌曲只会跳到开头。
我需要使用 http 流,因为有些文件非常大,无法将它们压缩/转码为更小的尺寸?
所以我的问题是:如何更改使用 http 流的音频文件的当前时间?
【问题讨论】:
标签: javascript node.js express html5-audio audio-streaming