Coo*_*dle 3 javascript youtube audio node.js express
我使用一个名为youtube-audio-stream 的库,它使用 Fluent-ffmpeg 和 ytdl-core 来从给定的 youtube 链接接收可读流,然后将其通过管道传输到响应对象,并使用我的 Express 服务器的端点作为源在我的 html 页面的音频标签中。
每当我加载 html 页面并尝试单击播放时,都会出现以下错误:
events.js:467
function arrayClone(arr, n) {
^
RangeError: Maximum call stack size exceeded
at arrayClone (events.js:467:20)
at PassThrough.emit (events.js:196:23)
at PassThrough.output.on.error (C:\development\ElectronTut\ytmp3\node_modules\youtube-audio-stream\index.js:38:16)
at PassThrough.emit (events.js:198:15)
at PassThrough.output.on.error (C:\development\ElectronTut\ytmp3\node_modules\youtube-audio-stream\index.js:38:16)
at PassThrough.emit (events.js:198:15)
at PassThrough.output.on.error (C:\development\ElectronTut\ytmp3\node_modules\youtube-audio-stream\index.js:38:16)
at PassThrough.emit (events.js:198:15)
at PassThrough.output.on.error (C:\development\ElectronTut\ytmp3\node_modules\youtube-audio-stream\index.js:38:16)
at PassThrough.emit (events.js:198:15)
Run Code Online (Sandbox Code Playgroud)
经过几个小时的研究,我终于放弃了,来到了这里。据我了解,当调用堆栈在进程的下一个周期开始之前没有正确清空时,就会触发此错误,大多数 stackoverflow 论坛一直在讨论异步编程如何导致潜在的无限循环,但我并没有弄乱周围没有足够近的地方可以理解这样的循环可以在流中发生的位置。
这是我的服务器代码:
const express = require("express");
const app = new express();
const stream = require('youtube-audio-stream');
const uri = "https://www.youtube.com/watch?v=t1TcDHrkQYg";
app.get("/audio", (req, res) => {
stream(uri).pipe(res);
})
app.listen(3000, () => console.log("Ready!"))
Run Code Online (Sandbox Code Playgroud)
我的前端代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Doc</title>
</head>
<body>
<audio autoplay controls>
<source src="http://localhost:3000/audio" type="audio/mpeg">
</audio>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果这听起来很愚蠢或者我做了一些愚蠢的事情,我谦虚地道歉,但我真的处于边缘并且失去了所有希望。我将如何解决或处理这个范围错误?如果您愿意的话,请问任何做过与我正在做的事情类似的事情的人,还有更好的选择吗?
非常感谢您付出的时间和精力。
修复了它,糟糕的库正在使用过时的 ytdl-core 版本!我下载了 youtube-audio-stream 的源代码,然后将 ytdl-core 更新到最新版本,现在一切正常了!
| 归档时间: |
|
| 查看次数: |
4870 次 |
| 最近记录: |