AudioPlayerState randomly turns to Idle after a while

Question was too long for discord, I made a stack overflow question and here's the link: https://stackoverflow.com/questions/77960972/discord-bot-player-state-randomly-changing-to-idle-and-therefore-stopping-playba
Stack Overflow
Discord bot player state randomly changing to idle and therefore st...
I know this has been asked before, under different titles. But yet none of the questions could answer my specific problem Okay, so this is a stupid problem. My discord.js bot randomly leaves the vo...
67 Replies
d.js toolkit
d.js toolkitโ€ข10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
dJs v14.14.1 nodeJS v20.11.0 i'm starting to think the problem is in the track itself i removed the connection.destroy() line and it just stops playing now and all logs say that the track is finished even though it's not
ThePedroo
ThePedrooโ€ข10mo ago
Well, it finished in some way
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
what way the track wasnt done
ThePedroo
ThePedrooโ€ข10mo ago
There's no more packets to be read, at least Discord.js can't find any more
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
and i don't suppose this is a network issue because i tried it on an online host but it just increased the time before cutting off
ThePedroo
ThePedrooโ€ข10mo ago
Have you tried to play the downloaded audio directly into your PC?
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
umm no because the audio isn't the same all the time
ThePedroo
ThePedrooโ€ข10mo ago
You should give a try to playing it as a local file So it may be the actual end for the downloaded stream
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
sorry for getting religion in, but the audio plays a different surah (chapter) of the quran depending on what the user chooses. I use a cdn made for that and the url is formatted like this: https://cdn.islamic.network/quran/audio-surah/128/${readerName}/${surahNumber}.mp3 It downloads an mp3 so i'm sure it's correctly formatted
ThePedroo
ThePedrooโ€ข10mo ago
It shouldn't matter what chapter it is. I'm mostly talking about downloading the mp3 that cuts into your PC and see the actual end with some player
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
and no because i actually memorized the surahs that i play, it's not the end. And i open https://quran.com/36 (36 is the chapter i usually test on) and follow along with it to see when it cuts off
Quran.com
Surah Ya-Sin - 1-83 - Quran.com
Read and listen to Surah Ya-Sin. The Surah was revealed in Mecca, ordered 36 in the Quran. The Surah title means "Ya Sin" in English and consists of 8...
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
all of them cut if theyre longer than 2 minutes or something exactly 129400ms is the time where none of them cut before all of them cut after or on that time (from my assumptions), probably because a few-second mp3 doesn't take too much resources
ThePedroo
ThePedrooโ€ข10mo ago
If you download them, and play as a local file, does it work or still cut? Seems more like a network issue
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
. sure let me try
ThePedroo
ThePedrooโ€ข10mo ago
At least on my PC it took several seconds for it even start to play, so I suppose this could be happening while playing
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
yeah that happens
ThePedroo
ThePedrooโ€ข10mo ago
Not necessarily from your side, but the website's part
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
but it's not music so people wait for it to load and then they listen
ThePedroo
ThePedrooโ€ข10mo ago
The website take long to send data, and all the data be read may be confused as an end by djs Well, if it is or not, it's an issue here as it may be confused with an end
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
well actually, it seems like the website (CDN) i'm using is segmentationally getting the audio, because the loading bar gets longer, and the second stopwatch increases as i listen
No description
ThePedroo
ThePedrooโ€ข10mo ago
I got the entire stream when I got the url from the website 17m of audio
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
oh you have the code from stack overflow
ThePedroo
ThePedrooโ€ข10mo ago
Nah
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
ah yes nvm
ThePedroo
ThePedrooโ€ข10mo ago
I got from the network tab
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
same for me, when i opened that link it loaded the whole thing
No description
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
but not with the website i use
ThePedroo
ThePedrooโ€ข10mo ago
That's from the website you sent
ThePedroo
ThePedrooโ€ข10mo ago
I mean this one: https://quran.com/36
Quran.com
Surah Ya-Sin - 1-83 - Quran.com
Read and listen to Surah Ya-Sin. The Surah was revealed in Mecca, ordered 36 in the Quran. The Surah title means "Ya Sin" in English and consists of 8...
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
oh yes, this website also offers audio maybe i should change providers and see?
ThePedroo
ThePedrooโ€ข10mo ago
Uhm, I thought you were using that one ๐Ÿคฃ
ThePedroo
ThePedrooโ€ข10mo ago
You can either load all those segments into a master stream and send to djs Or use that website that loads the entire thing
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
the website doesnt load the entire thing that's the issue
ThePedroo
ThePedrooโ€ข10mo ago
I mean, the quran.com one
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
yes
ThePedroo
ThePedrooโ€ข10mo ago
17m isn't the entire stream?
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
i meant "oh alr" 17m is the entire one for the quran.com stream
ThePedroo
ThePedrooโ€ข10mo ago
Let me rephrase
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
ill have to wait the length of the entire chapter i suppose? some can reach 2 hours...
ThePedroo
ThePedrooโ€ข10mo ago
1. You can create a Node.js stream, and create multiple http requests filling up the stream (make it synchronous, in order) 2. You can use another source Nope
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
ill have to recode the url logic because quran.com's url works differently
ThePedroo
ThePedrooโ€ข10mo ago
You'll be loading while it plays, just like your browser do
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
i'm not sure how to do that
ThePedroo
ThePedrooโ€ข10mo ago
Let me do an example
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
cuz i prefer the https://cdn.islamic.network/quran/audio-surah/128/whatever CDN because it has more and better readers thanks
ThePedroo
ThePedrooโ€ข10mo ago
const mainStream = new PassThrough()

const arrOfLinks = [ .. . .. . . .. ]

for (let i = 0;i < arrOfLinks.length;i++) {
await new Promise((resolve) => {
https.get(arrOfLinks, (res) => {
res.on('error', (err) => {
// Handle errors
})
res.on('data', (d) => mainStream.push(d))

if (i == arrOfLinks.length) res.on('end', () => mainStream.push(null))
})
})
}

mainStream.once('readable', () => {
// Use mainstream here
})
const mainStream = new PassThrough()

const arrOfLinks = [ .. . .. . . .. ]

for (let i = 0;i < arrOfLinks.length;i++) {
await new Promise((resolve) => {
https.get(arrOfLinks, (res) => {
res.on('error', (err) => {
// Handle errors
})
res.on('data', (d) => mainStream.push(d))

if (i == arrOfLinks.length) res.on('end', () => mainStream.push(null))
})
})
}

mainStream.once('readable', () => {
// Use mainstream here
})
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
what should arr of links be?
ThePedroo
ThePedrooโ€ข10mo ago
The url of the segments
ThePedroo
ThePedrooโ€ข10mo ago
GitHub
NodeLink/src/sources/soundcloud.js at main ยท PerformanC/NodeLink
Performant LavaLink alternative written with Node.Js - PerformanC/NodeLink
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
it's only one url, but it looks like it uses segments
ThePedroo
ThePedrooโ€ข10mo ago
It loads HLS, which is also segmented
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
let me try the network tab
ThePedroo
ThePedrooโ€ข10mo ago
You need to discover what's the url of the segments for that
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
oh my
No description
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
same url
ThePedroo
ThePedrooโ€ข10mo ago
Take a better look
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
anyways i'll have to go now, 1:08 AM, thank you for helping
ThePedroo
ThePedrooโ€ข10mo ago
It may not be the same
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
i checked
ThePedroo
ThePedrooโ€ข10mo ago
Sure, no problem!
Proman4713 ๐Ÿ‡ต๐Ÿ‡ธ
will you be available tmrw?
ThePedroo
ThePedrooโ€ข10mo ago
Yep
Want results from more Discord servers?
Add your server