|
|
@ -722,6 +722,8 @@ class AudioPlayer(threading.Thread): |
|
|
|
self._current_error: Optional[Exception] = None |
|
|
|
self._lock: threading.Lock = threading.Lock() |
|
|
|
|
|
|
|
self._end_future = client.loop.create_future() |
|
|
|
|
|
|
|
if after is not None and not callable(after): |
|
|
|
raise TypeError('Expected a callable for the "after" parameter.') |
|
|
|
|
|
|
@ -779,7 +781,8 @@ class AudioPlayer(threading.Thread): |
|
|
|
self.stop() |
|
|
|
finally: |
|
|
|
self._call_after() |
|
|
|
self.source.cleanup() |
|
|
|
self._cleanup() |
|
|
|
self.client.loop.call_soon_threadsafe(self._end_future.set_result, self._current_error) |
|
|
|
|
|
|
|
def _call_after(self) -> None: |
|
|
|
error = self._current_error |
|
|
@ -793,6 +796,12 @@ class AudioPlayer(threading.Thread): |
|
|
|
elif error: |
|
|
|
_log.exception('Exception in voice thread %s', self.name, exc_info=error) |
|
|
|
|
|
|
|
def _cleanup(self) -> None: |
|
|
|
try: |
|
|
|
self.source.cleanup() |
|
|
|
except Exception: |
|
|
|
_log.exception("Error cleaning up audio source %s", self.source) |
|
|
|
|
|
|
|
def stop(self) -> None: |
|
|
|
self._end.set() |
|
|
|
self._resumed.set() |
|
|
@ -822,6 +831,9 @@ class AudioPlayer(threading.Thread): |
|
|
|
self.source = source |
|
|
|
self.resume(update_speaking=False) |
|
|
|
|
|
|
|
async def wait_async(self) -> Optional[Exception]: |
|
|
|
return await self._end_future |
|
|
|
|
|
|
|
def _speak(self, speaking: SpeakingState) -> None: |
|
|
|
try: |
|
|
|
asyncio.run_coroutine_threadsafe(self.client.ws.speak(speaking), self.client.client.loop) |
|
|
|