Pycord-Development / pycord

Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python
https://docs.pycord.dev
MIT License
2.71k stars 458 forks source link

Audio Source Positon/Timestamp (Stream Progress) #126

Closed kilkuwu closed 3 years ago

kilkuwu commented 3 years ago

Summary

Adding a position/stream_progress property to voice_client.py

What is the feature request for?

The core library

The Problem

Currently, there is no such property in voice_client.py that returns the stream time of a track/audio_source.

I am writing a discord music bot and it will be much easier for me to implement the forward/rewind commands if Pycord has this feature as the stream progress is required to exactly get back or go to the timestamp of a track.

The Ideal Solution

The property should return the position of the playing audio source. (preferably in milliseconds)

The Current Solution

As far as I know, there is currently no stable solution that a normal developer could come up with.

However, I made a count progress asynchronous function that counts the progress (in seconds) of a playing track. This solution is really unstable as sometimes the function breaks and stops working.

Additional Context

I believe there is a similar feature in discord.js. In discord.js v12 there used to be a StreamDispatcher which had a StreamDispatcher.streamTime property which was further removed in v13 (discord.js) and is being re-added as per this commit on the official Discord.js repository.

zeffo commented 3 years ago

You can implement this yourself by subclassing your AudioSource. Here is an example:

class CustomAudio(PCMVolumeTransformer):
    played = 0

    def read(self):
        self.played += 20
        return super().read()

You can use VoiceClient.source.played to get the time in ms.

kilkuwu commented 3 years ago

didnt know about this. thanks

zeffo commented 3 years ago

Also, you mentioned wanting to implement forward/rewind commands. Are you using an FFMPEG based AudioSource? If so, you can use the -ss flag to easily create forward/rewind commands.

kilkuwu commented 3 years ago

I do know that, i used the -ss flag in my seek command. However, I do wonder should i pause the playback or stop it completely before playing the source again with a different start position.