Skip to content

Commit 441a6b7

Browse files
committed
Read first segment from source before starting playback
1 parent e09c607 commit 441a6b7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

discord/player.py

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

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

@@ -740,7 +743,13 @@ def _do_run(self) -> None:
740743
self._start = time.perf_counter()
741744

742745
self.loops += 1
743-
data = self.source.read()
746+
# Send the data read from the start of the function if it is not None
747+
if first_data is not None:
748+
data = first_data
749+
first_data = None
750+
# Else read the next bit from the source
751+
else:
752+
data = self.source.read()
744753

745754
if not data:
746755
self.stop()

0 commit comments

Comments
 (0)