@@ -734,6 +734,7 @@ def __init__(self, source: AudioSource, client: VoiceClient, *, after=None):
734734 self ._current_error : Exception | None = None
735735 self ._connected : threading .Event = client ._connected
736736 self ._lock : threading .Lock = threading .Lock ()
737+ self ._played_frames_offset : int = 0
737738
738739 if after is not None and not callable (after ):
739740 raise TypeError ('Expected a callable for the "after" parameter.' )
@@ -761,10 +762,12 @@ def _do_run(self) -> None:
761762 # wait until we are connected
762763 self ._connected .wait ()
763764 # reset our internal data
765+ self ._played_frames_offset += self .loops
764766 self .loops = 0
765767 self ._start = time .perf_counter ()
766768
767769 self .loops += 1
770+
768771 # Send the data read from the start of the function if it is not None
769772 if first_data is not None :
770773 data = first_data
@@ -819,6 +822,7 @@ def pause(self, *, update_speaking: bool = True) -> None:
819822 self ._speak (False )
820823
821824 def resume (self , * , update_speaking : bool = True ) -> None :
825+ self ._played_frames_offset += self .loops
822826 self .loops = 0
823827 self ._start = time .perf_counter ()
824828 self ._resumed .set ()
@@ -844,3 +848,7 @@ def _speak(self, speaking: bool) -> None:
844848 )
845849 except Exception as e :
846850 _log .info ("Speaking call in player failed: %s" , e )
851+
852+ def played_frames (self ) -> int :
853+ """Gets the number of 20ms frames played since the start of the audio file."""
854+ return self ._played_frames_offset + self .loops
0 commit comments