I use a library called youtube-audio-stream that uses fluent-ffmpeg and ytdl-core in order to receive a readable stream from a given youtube link, then pipe it to the response object and use that endpoint of my express server as the source in an audio tag in my html page.
Whenever I do load the html page and try to click play, it gives me the following error:
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)
After hours of research, I finally gave up and came here. From what I understand, this error is fired when the call stack is not emptied out properly before the next tick of a process begins, most stackoverflow forums kept going on about how asynchronous programming leads to a potential infinite loop, but I haven't messed around no where near enough to understand where such a loop can occur in a stream.
Here's my server code:
const express = require("express");
const app = new express();
const stream = require('youtube-audio-stream');
const uri = "";
app.get("/audio", (req, res) => {
stream(uri).pipe(res);
})
app.listen(3000, () => console.log("Ready!"))
My frontend code:
<!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>
I humbly apologize if this sounds stupid or I've done something stupid but I'm really at an edge and have lost all hope. How would I go about solving or handling this range error? If you would be so kind, please to anyone who's done something similar to what I'm doing, are there better alternatives?
Thank you very much for your time and effort.
I use a library called youtube-audio-stream that uses fluent-ffmpeg and ytdl-core in order to receive a readable stream from a given youtube link, then pipe it to the response object and use that endpoint of my express server as the source in an audio tag in my html page.
Whenever I do load the html page and try to click play, it gives me the following error:
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)
After hours of research, I finally gave up and came here. From what I understand, this error is fired when the call stack is not emptied out properly before the next tick of a process begins, most stackoverflow forums kept going on about how asynchronous programming leads to a potential infinite loop, but I haven't messed around no where near enough to understand where such a loop can occur in a stream.
Here's my server code:
const express = require("express");
const app = new express();
const stream = require('youtube-audio-stream');
const uri = "https://www.youtube./watch?v=t1TcDHrkQYg";
app.get("/audio", (req, res) => {
stream(uri).pipe(res);
})
app.listen(3000, () => console.log("Ready!"))
My frontend code:
<!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>
I humbly apologize if this sounds stupid or I've done something stupid but I'm really at an edge and have lost all hope. How would I go about solving or handling this range error? If you would be so kind, please to anyone who's done something similar to what I'm doing, are there better alternatives?
Thank you very much for your time and effort.
Share Improve this question asked Jun 14, 2019 at 15:21 CoodleNoodleCoodleNoodle 3543 silver badges20 bronze badges 02 Answers
Reset to default 5Fixed it, the lousy library was using an outdated version of ytdl-core! I downloaded the source of youtube-audio-stream and then updated the ytdl-core to the latest version, now all of it works!
Here is a solution that works without the server-side.
I (also) spent hours trying to get this working...
I looked into youtube-audio-stream
after seeing your post, but I never got it working. Instead I ended up with this solution that seems to work well. After reading this post, I modified some values to work with YouTube's current (2020) API.
Here is a solution that should work, for anyone looking! Try on CodePen
// YouTube video ID
var videoID = "CMNry4PE93Y";
// Fetch video info (using a proxy if avoid CORS errors)
fetch('https://cors-anywhere.herokuapp./' + "https://www.youtube./get_video_info?video_id=" + videoID).then(response => {
if (response.ok) {
response.text().then(ytData => {
// parse response to find audio info
var ytData = parse_str(ytData);
var getAdaptiveFormats = JSON.parse(ytData.player_response).streamingData.adaptiveFormats;
var findAudioInfo = getAdaptiveFormats.findIndex(obj => obj.audioQuality);
// get the URL for the audio file
var audioURL = getAdaptiveFormats[findAudioInfo].url;
// update the <audio> element src
var youtubeAudio = document.getElementById('youtube');
youtubeAudio.src = audioURL;
});
}
});
function parse_str(str) {
return str.split('&').reduce(function(params, param) {
var paramSplit = param.split('=').map(function(value) {
return decodeURIComponent(value.replace('+', ' '));
});
params[paramSplit[0]] = paramSplit[1];
return params;
}, {});
}
<audio id="youtube" controls></audio>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744225221a4563971.html
评论列表(0条)