From 226ad3a22cd3bbffdf61e852624f76384ea6ce9b Mon Sep 17 00:00:00 2001 From: and <46562212+DevAndromeda@users.noreply.github.com> Date: Fri, 5 Nov 2021 11:38:40 +0545 Subject: [PATCH] docs: add working mechanism --- docs/faq/how_does_it_work.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/faq/how_does_it_work.md diff --git a/docs/faq/how_does_it_work.md b/docs/faq/how_does_it_work.md new file mode 100644 index 0000000..78a8133 --- /dev/null +++ b/docs/faq/how_does_it_work.md @@ -0,0 +1,22 @@ +# How does Discord Player actually work? + +- Discord Player can be used by first initializing `Player` class with your discord.js client. Discord Player uses `Queue` to assign queue manager to individual guild. +Which means each guild will have its own queue object. Every player action has to go through the `Queue` object for example, `play`, `pause`, `volume` etc. + +- When `Player` is initialized, it creates a cache to store external extractors or queues information. Queue is created by calling `createQueue` method of `Player` instance. +A client should have only one `Player` instance, otherwise it will be complicated to track queues and other metadata. + +- Searching tracks can be done via `search` method of `Player` instance. Discord Player offers `search engine` option to target specific searches. Discord Player first +calls all the registered extractors first with the search query. If all external extractors failed to validate the query, player then passes the query to built-in extractors. +Invalid or unknown queries may return `arbitrary` result. + +- The track result obtained from `search` can be loaded into `Queue` by calling `queue.addTrack`/`queue.addTracks`/`queue.play`. + +- Player calls `onBeforeCreateStream` if user has enabled the function while creating queue. This method runs each time before stream is downloaded. Users may use it +to modify how and which stream will be played. + +- Queue is based on FIFO method (First In First Out) + +- Final stream is a pcm format, required for volume controls which is created by Discord Player itself. + +- All the audio filters are handled by FFmpeg and stream has to reload in order to update filters.