@@ -724,6 +724,7 @@ def __init__(self, source: AudioSource, client: VoiceClient, *, after=None):
724
724
self ._current_error : Exception | None = None
725
725
self ._connected : threading .Event = client ._connected
726
726
self ._lock : threading .Lock = threading .Lock ()
727
+ self ._played_frames_offset : int = 0
727
728
728
729
if after is not None and not callable (after ):
729
730
raise TypeError ('Expected a callable for the "after" parameter.' )
@@ -751,10 +752,12 @@ def _do_run(self) -> None:
751
752
# wait until we are connected
752
753
self ._connected .wait ()
753
754
# reset our internal data
755
+ self ._played_frames_offset += self .loops
754
756
self .loops = 0
755
757
self ._start = time .perf_counter ()
756
758
757
759
self .loops += 1
760
+
758
761
# Send the data read from the start of the function if it is not None
759
762
if first_data is not None :
760
763
data = first_data
@@ -809,6 +812,7 @@ def pause(self, *, update_speaking: bool = True) -> None:
809
812
self ._speak (False )
810
813
811
814
def resume (self , * , update_speaking : bool = True ) -> None :
815
+ self ._played_frames_offset += self .loops
812
816
self .loops = 0
813
817
self ._start = time .perf_counter ()
814
818
self ._resumed .set ()
@@ -834,3 +838,7 @@ def _speak(self, speaking: bool) -> None:
834
838
)
835
839
except Exception as e :
836
840
_log .info ("Speaking call in player failed: %s" , e )
841
+
842
+ def played_frames (self ) -> int :
843
+ """Gets the number of 20ms frames played since the start of the audio file."""
844
+ return self ._played_frames_offset + self .loops
0 commit comments