我正在托管一个小型播客提要,在我最终将其连接到 Downcast 后,一切正常,直到我尝试向前/向后跳。我终于意识到寻找本质上并不是管道流的一部分。我四处搜寻,似乎找不到任何有用的东西。
使用以下代码,我将如何实现查找?
app.get('/stream/:id', function(req, res) {
if (!req.params.id) {
res.status(404);
res.send("Not found");
}
var filePath = path.join(Config.media, '**' , req.params.id);
filePath = glob.sync(filePath)[0];
var stat = fs.statSync(filePath);
res.writeHead(200, {
'Content-Type': 'audio/mpeg',
'Content-Length': stat.size,
'Accept-Ranges': 'bytes'
});
var readStream = fs.createReadStream(filePath);
readStream.pipe(res);
});
最佳答案
我实际上可以使用visionmedia/send来做到这一点(它也处理了我的很多路径工作)。
这是用于查找的新代码:
var send = require('send');
...
app.get('/stream/*', function(req, res) {
var path = Url.parse(req.url).pathname.replace('/stream','');
send(req, path)
.root(Config.media)
.on('error', function(err) {
res.statusCode = err.status || 500;
res.end(err.message);
})
.on('directory', function() {
res.statusCode = 403;
res.end("Forbidden");
})
.pipe(res);
});
关于node.js - 如何将搜索与 Node Express 音频流结合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22284756/