Elapsed audio resource duration
Hello everyone,
I'm currently trying to implement a proper progress bar which displays the playback of the current song.
According to a few questions online, it seems like discord.js used to have a
streamTime
property. It looks like this has been removed for some reason in the next release.
- Why has this been removed?
- Is there any replacement or other way to get the current position in millis? I saw https://discord.js.org/#/docs/voice/main/class/AudioResource?scrollTo=playbackDuration, but this seems to be something different.
I am playing the resource using this method:
https://github.com/manuel-rw/jellyfin-discord-music-bot/blob/92021dd94e824af91a559d161df11b2898812595/src/clients/discord/discord.voice.service.ts#L8712 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
NPM:
9.1.2
Yarn: 3.3.0
Node: v16.17.1
discord.js: 14.7.1
Code:
https://github.com/manuel-rw/jellyfin-discord-music-bot/blob/92021dd94e824af91a559d161df11b2898812595/src/clients/discord/discord.voice.service.ts#L87I think get the audio resource time in ms and divide the .playbackDuration value by the resource time is good way.
Does that really give the elapsed time?
Sounds like it will just always give 1, when both playback duration and resource time is the same value.
If not, what do those individual values mean?
Also, do you know why the previous behaviour has been removed? This just seems unnecessary when there's a simpler way
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Thank you, I'll have a look at it 👍
I looked into this again,
1. I do not understand your sentence here:
meant to be generic and to encompass most or all use cases to where the developer can tailor the experience, performance impact
. Why should a library, made for playing music, not keep track of time? This seems like making a car and forgetting to produce the wheels.
2. I do not see a easy solution in the Volcano bot. It seems cumbersome and much boilerplate code.
3. The only solution, I have came up yet is, to read the time from the AudioResource
, record an initial timestamp and keep track of this. Since pauses or potential steam lags could break this, I would have to implement all edge cases to record the timestamps and store them in a list. Then, I would have to calculate the elapsed time from the list. I know that this can be done, but this implementation screams for inaccurate measurements.
I do not see any value in abstracting the elapsed time. Why would discord.js do that? I fully understand, that things like currentTrack
would not make sense to be implemented in discord.js, as this would not be generic and abstracted, but the elapsed time seems like a huge oversight to me?
Apparently V12 (or V13) had a dispatcher, that stored the (accurate) elapsed time. I did a search, if there was any replacement for this in V14, but seems like it was just blindly removed. I understand, that the goal is to keep things modular and generic, but this seems like an incomplete solution? I searched through the majority of projects on GitHub, that have the discord.js tag, and most seem to stay on an older version for this exact reason.
If the goal is, to keep things generic, why not make a new library that integrates with the existing ones? Funnily the docs also never state anything about seeking or elapsed time, which is an essential feature in my opinion.
PS: I don't blame anyone specific. Not exposing this information seems like a huge anti-experience thing to do to me.
--------
The only place, where I was able to find a decent looking solution, was here:
https://github.com/adh319/Lunox/blob/e95ad3c4ef1d98c93bb4cd1273be1acc275dd912/src/commands/Slash/Music/Seek.js#L43
However, I don't fully understand where this function comes from or how it works.
Any update on this?Maybe nothing man
It seems that you should ask community of packages which you are using currently
to my knowledge
<AudioResource>.playbackDuration
and <AudioPlayer>.state.playbackDuration
are intended to be a rough elapsed duration
it starts at 0 and is incremented as the resource playsHmm okay, I will check those out. Thanks
Can confirm that this works. Why is this not in the documentation? 😄
I think it should be included here: https://discordjs.guide/voice/audio-resources.html#cheat-sheet
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Also, I didn't find
<AudioPlayer>.state.playbackDuration
with TS. But the other one workswith ts, you'd need to typeguard by checking the status first
playbackDuration
only exists on Playing
and Paused
states
Why is this not in the documentation?it is, and in the OP you shared the link to it (though admittedly since then the new docs site has been released https://discord.js.org/docs/packages/voice/main/AudioResource:Class#playbackDuration) that you arrived at the conclusion it's something different was just a misinterpretation of what it was for I believe the voice guide is incomplete because /voice is still considered incomplete but on top of that it wouldn't really make sense to list all features in the guide since that's what the docs are for the guide just has popular use cases currently