From 5a123389aeaaf713fa3c4489d10307047ea613cf Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sat, 25 Mar 2023 20:16:08 +0800 Subject: [PATCH] fetch up pyglet --- libs/pyglet/media/drivers/__init__.py | 88 +++++++++++++++------------ 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/libs/pyglet/media/drivers/__init__.py b/libs/pyglet/media/drivers/__init__.py index 822143a..e8ce0a6 100644 --- a/libs/pyglet/media/drivers/__init__.py +++ b/libs/pyglet/media/drivers/__init__.py @@ -1,55 +1,63 @@ """Drivers for playing back media.""" +import sys import atexit import pyglet _debug = pyglet.options['debug_media'] +_is_pyglet_doc_run = hasattr(sys, "is_pyglet_doc_run") and sys.is_pyglet_doc_run -for driver_name in pyglet.options['audio']: - try: - if driver_name == 'pulse': - from . import pulse - - _audio_driver = pulse.create_audio_driver() - break - elif driver_name == 'xaudio2': - if pyglet.compat_platform in ('win32', 'cygwin'): - from pyglet.libs.win32.constants import WINDOWS_8_OR_GREATER - - if WINDOWS_8_OR_GREATER: - from . import xaudio2 - - _audio_driver = xaudio2.create_audio_driver() - break - elif driver_name == 'directsound': - if pyglet.compat_platform in ('win32', 'cygwin'): - from . import directsound - - _audio_driver = directsound.create_audio_driver() - break - elif driver_name == 'openal': - from . import openal - - _audio_driver = openal.create_audio_driver() - break - elif driver_name == 'silent': - from . import silent - - _audio_driver = silent.create_audio_driver() - break - except Exception: - if _debug: - print(f'Error importing driver {driver_name}:') - import traceback - - traceback.print_exc() -else: +if _is_pyglet_doc_run: from . import silent - _audio_driver = silent.create_audio_driver() +else: + + for driver_name in pyglet.options['audio']: + try: + if driver_name == 'pulse': + from . import pulse + + _audio_driver = pulse.create_audio_driver() + break + elif driver_name == 'xaudio2': + if pyglet.compat_platform in ('win32', 'cygwin'): + from pyglet.libs.win32.constants import WINDOWS_8_OR_GREATER + + if WINDOWS_8_OR_GREATER: + from . import xaudio2 + + _audio_driver = xaudio2.create_audio_driver() + break + elif driver_name == 'directsound': + if pyglet.compat_platform in ('win32', 'cygwin'): + from . import directsound + + _audio_driver = directsound.create_audio_driver() + break + elif driver_name == 'openal': + from . import openal + + _audio_driver = openal.create_audio_driver() + break + elif driver_name == 'silent': + from . import silent + + _audio_driver = silent.create_audio_driver() + break + except Exception: + if _debug: + print(f'Error importing driver {driver_name}:') + import traceback + + traceback.print_exc() + + else: + from . import silent + _audio_driver = silent.create_audio_driver() + def get_audio_driver(): """Get the preferred audio driver for the current platform.