我目前正在尝试部署自己制作的音乐展示台。它适用于所有情况,但当我单击歌曲从搜索栏播放时除外。我继续收到“ 503(服务不可用)”。有人知道我的代码怎么了吗?我在过去6个小时中一直在努力寻找答案,但是我什么也没想出来。
这是我的Heroku日志:
2018-08-10T01:47:00.757554+00:00 app[web.1]: events.js:183
2018-08-10T01:47:00.757570+00:00 app[web.1]: throw er; // Unhandled 'error' event
2018-08-10T01:47:00.757572+00:00 app[web.1]: ^
2018-08-10T01:47:00.757573+00:00 app[web.1]:
2018-08-10T01:47:00.757574+00:00 app[web.1]: TypeError: Invalid non-string/buffer chunk
2018-08-10T01:47:00.757576+00:00 app[web.1]: at validChunk (_stream_writable.js:254:10)
2018-08-10T01:47:00.757577+00:00 app[web.1]: at PassThrough.Writable.write (_stream_writable.js:288:21)
2018-08-10T01:47:00.757578+00:00 app[web.1]: at PassThrough.Writable.end (_stream_writable.js:563:10)
2018-08-10T01:47:00.757581+00:00 app[web.1]: at emitThree (events.js:141:20)
2018-08-10T01:47:00.757582+00:00 app[web.1]: at DestroyableTransform.emit (events.js:217:7)
2018-08-10T01:47:00.757583+00:00 app[web.1]: at emitThree (events.js:136:13)
2018-08-10T01:47:00.757585+00:00 app[web.1]: at FfmpegCommand.emit (events.js:217:7)
2018-08-10T01:47:00.757586+00:00 app[web.1]: at emitEnd (/app/node_modules/fluent-ffmpeg/lib/processor.js:424:16)
2018-08-10T01:47:00.757588+00:00 app[web.1]: at /app/node_modules/fluent-ffmpeg/lib/processor.js:433:16
2018-08-10T01:47:00.757589+00:00 app[web.1]: at /app/node_modules/async/dist/async.js:473:16
2018-08-10T01:47:00.765330+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-08-10T01:47:00.765674+00:00 app[web.1]: npm ERR! errno 1
2018-08-10T01:47:00.766812+00:00 app[web.1]: npm ERR! yuen@1.0.0 start: `node server.js`
2018-08-10T01:47:00.766955+00:00 app[web.1]: npm ERR! Exit status 1
2018-08-10T01:47:00.767136+00:00 app[web.1]: npm ERR!
2018-08-10T01:47:00.767256+00:00 app[web.1]: npm ERR! Failed at the yuen@1.0.0 start script.
2018-08-10T01:47:00.767393+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-08-10T01:47:00.771128+00:00 app[web.1]:
2018-08-10T01:47:00.771274+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-08-10T01:47:00.771356+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-08-10T01_47_00_768Z-debug.log
这是我的Express应用(server.js
)的源代码:
var express = require('express');
var youtubeStream = require('youtube-audio-stream');
var app = express();
app.use(express.static(__dirname));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
app.get('/stream/:videoId', function (req, res) {
try {
youtubeStream(req.params.videoId).pipe(res);
} catch (exception) {
res.status(500).send(exception);
}
});
app.listen(process.env.PORT || 3000, function () {
console.log('app is listening on port 3000!');
});
以下是通过发送xhr请求与服务器实际交互的代码:
function loadSound(vidID) {
context.close()
.then(() => {
context = new AudioContext();
analyser = context.createAnalyser();
analyser.fftSize = 32;
})
.then(() => {
var request = new XMLHttpRequest();
request.open("GET", window.location.href+"stream/"+vidID, true);
request.responseType = "arraybuffer";
request.onload = function() {
var Data = request.response;
process(Data);
};
request.send();
});
}
function process(Data) {
source = context.createBufferSource();
context.decodeAudioData(Data, function(buffer){
source.buffer = buffer;
source.connect(context.destination);
source.connect(analyser);
source.start(context.currentTime);
});
document.getElementById('searchBar').disabled = false;
loading(true);
}
最后,这是我的package.json
文件中列出的依赖项:
"dependencies": {
"express": "^4.16.3",
"ffmpeg": "0.0.4",
"fluent-ffmpeg": "^2.1.2",
"through2": "^2.0.3",
"xtend": "^4.0.1",
"youtube-audio-stream": "https://github.com/cryptagoras/youtube-audio-stream/archive/patch-3.tar.gz",
"ytdl-core": "^0.24.0"
}
答案 0 :(得分:1)
我找到了答案:我实际上没有在Heroku上安装任何编码库。我只是将ffmpeg
添加到了.buildpacks
中,现在一切都变得很吸引人了!