所以我不确定这是否可行。但是遇到了一个小问题,我不想跳过30秒,而是希望用户跳过(因为我们为在线收听播放了一个不同的音频文件),所以似乎暂停了直播,然后注入广告-或我们想要收听的文件听而不是直播。
然后,当我们希望用户听到的文件结束时,它就会恢复。而且听众仍然得到我们希望他们跳过的广播(这就是我们播放mp3的原因)
这是完整的代码
var http = require('http'),
Router = require('router'),
compression = require('compression'),
finalhandler = require('finalhandler'),
request = require('request'),
icecast = require('icecast-stack');
var router = Router()
var server = http.createServer(function onRequest(req, res) {
router(req, res, finalhandler(req, res))
})
router.use(compression())
// handle `GET` requests to `/DRN1`
router.get('/DRN1', function (req, res) {
let station = 'http://stream.radiomedia.com.au:8003/stream';
let remote = station;
var stream = icecast.createReadStream(station);
var remoteUrl = remote;
var ad = 0;
res.writeHead(200, {
'Content-Type': 'audio/mpeg'
});
stream.on('connect', function() {
console.error("Radio Stream connected!");
});
stream.on('metadata', function(metadata) {
var title = icecast.parseMetadata(metadata).StreamTitle;
if(title.indexOf("Advert") > -1){
ad = 1;
if(ad === 1)
{
// console.error(title);
let remote='https://storage.googleapis.com/ad-system/DRN1_Indie.drn1.com.mp3';
remoteUrl = remote+"?=Player" + req.url;
request.get(remoteUrl)
.on('response', response => {
response.pipe(res,{end:false});
//response.pipe(res);
})
.on("finish", response => {
ad = 0;
});
}
}
else{
console.error(title);
}
});
remoteUrl = station+"?=Player" + req.url;
request(remoteUrl).pipe(res);
});
server.listen(8080)
因此,简而言之,我如何完成原始流管道的播放广告并重新启动原始流。