问:节点JS-Mp3播放,然后重定向广播流

时间:2019-02-22 19:56:52

标签: node.js server stream shoutcast

我需要制作一个对媒体播放器做出响应的服务器(VLC,MPC ...),它必须先播放我的mp3文件,然后继续播放带有shoutcast服务器URL的流。 (或重定向该网址)

这是我的代码:

var http = require('http'),
    fileSystem = require('fs'),
    path = require('path'),
    util = require('util');

http.createServer(function(request, response) {
    var filePath = 'intro.mp3';
    var stat = fileSystem.statSync(filePath);
    console.log("bağlandı");
    response.writeHead(200, {
       'Content-Type': 'audio/mpeg',
      'Content-Length': stat.size
  });

    //First Part
    stream = fileSystem.createReadStream(filePath);
    stream.on('data', function (chunk) {
          response.write(chunk);
         }); 
      //End First Part   
      //Second Part            
      response.writeHead(301, {Location: 'http://192.162.138.62:8000/'});
      response.end();
      //End Second Part   

})
.listen(2000);

第一部分是播放我的“ intro.mp3”文件。当只有第一部分存在时,就可以了。 VLC播放器可以使用URL localhost:2000

播放“ intro.mp3”

第二部分是重定向实时流服务器。仅当这部分存在时,VLC还可使用URL localhost:2000(重定向http://192.162.138.62:8000/)播放我的原始流

我需要先播放mp3,然后继续运行服务器并播放http://192.162.138.62:8000/此流。

0 个答案:

没有答案
相关问题