节点-找不到音频流 [英] Node - Can't seek audio stream

查看:94
本文介绍了节点-找不到音频流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的服务器,该服务器使用fs模块将mp3文件流式传输到浏览器,并以html5音频元素播放该文件.照原样,音频流非常好,但是,即使我要搜索的部分已经被缓冲,我也无法在音频流中进行搜索.

I have created a simple server that uses the fs module to stream an mp3 file to a browser which plays it in an html5 audio element. As it is, the audio streams perfectly fine, however, I can't seek through the stream, even if the part I seek to has already been buffered.

var express = require('express');
var app = express();
var fs = require('fs');

app.get('/', function (req, res) {
    var filePath = 'music.mp3';
    var stat = fs.statSync(filePath);

    res.writeHead(200, {
        'Content-Type': 'audio/mpeg',
        'Content-Length': stat.size,
    });

    var readStream = fs.createReadStream(filePath);
    readStream.pipe(res);
});

其他类似的问与答建议添加Content-Range标头,但我找不到如何做到这一点的简单示例.其他人已经说过使用206 Partial-Content标头,但是当我这样做时,音频将根本无法播放.

Other similar Q&As have suggested to add the Content-Range header, but I can't find a simple example of how to do that. Others have said to use the 206 Partial-Content header, but when I do that the audio won't play at all.

这是演示(在Windows的chrome上测试)

Here's a demo (testing on chrome on windows)

推荐答案

来自

这篇关于节点-找不到音频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆