Skip to content

Commit

Permalink
fix: audio plays in fast forward for first few seconds (#2584)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Sep 21, 2024
1 parent 1051ffa commit ebde918
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2577](https://github.com/Pycord-Development/pycord/pull/2577))
- Fixed `codec` option for `FFmpegOpusAudio` class to make it in line with
documentation. ([#2581](https://github.com/Pycord-Development/pycord/pull/2581))
- Fixed a possible bug where audio would play too fast at the beginning of audio files.
([#2584](https://github.com/Pycord-Development/pycord/pull/2584))

### Changed

Expand Down
11 changes: 10 additions & 1 deletion discord/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,9 @@ def __init__(self, source: AudioSource, client: VoiceClient, *, after=None):
raise TypeError('Expected a callable for the "after" parameter.')

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

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

self.loops += 1
data = self.source.read()
# Send the data read from the start of the function if it is not None
if first_data is not None:
data = first_data
first_data = None
# Else read the next bit from the source
else:
data = self.source.read()

if not data:
self.stop()
Expand Down

0 comments on commit ebde918

Please sign in to comment.