Skip to content

Commit 52f7f65

Browse files
felix920506Lulalaby
authored andcommitted
fix: audio plays in fast forward for first few seconds (Pycord-Development#2584)
* Read first segment from source before starting playback * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md Signed-off-by: Lala Sabathil <[email protected]> --------- Signed-off-by: felix920506 <[email protected]> Signed-off-by: Lala Sabathil <[email protected]> Co-authored-by: Lala Sabathil <[email protected]> Co-authored-by: Lala Sabathil <[email protected]>
1 parent b154fb3 commit 52f7f65

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ These changes are available on the `master` branch, but have not yet been releas
2929
([#2577](https://github.com/Pycord-Development/pycord/pull/2577))
3030
- Fixed `codec` option for `FFmpegOpusAudio` class to make it in line with
3131
documentation. ([#2581](https://github.com/Pycord-Development/pycord/pull/2581))
32+
- Fixed a possible bug where audio would play too fast at the beginning of audio files.
33+
([#2584](https://github.com/Pycord-Development/pycord/pull/2584))
3234

3335
### Changed
3436

discord/player.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,9 @@ def __init__(self, source: AudioSource, client: VoiceClient, *, after=None):
729729
raise TypeError('Expected a callable for the "after" parameter.')
730730

731731
def _do_run(self) -> None:
732+
# attempt to read first audio segment from source before starting
733+
# some sources can take a few seconds and may cause problems
734+
first_data = self.source.read()
732735
self.loops = 0
733736
self._start = time.perf_counter()
734737

@@ -752,7 +755,13 @@ def _do_run(self) -> None:
752755
self._start = time.perf_counter()
753756

754757
self.loops += 1
755-
data = self.source.read()
758+
# Send the data read from the start of the function if it is not None
759+
if first_data is not None:
760+
data = first_data
761+
first_data = None
762+
# Else read the next bit from the source
763+
else:
764+
data = self.source.read()
756765

757766
if not data:
758767
self.stop()

0 commit comments

Comments
 (0)