You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After trying to work around win32, macos and linux bugs I've gone ahead and removed playsound from my python project and replaced it with this cross platform solution.
"""Sound utilities."""importosimportsysimporttimefromsubprocessimportcheck_callimportwarningsdefplayaudio(file: str, ignore_errors=True) ->None:
assertos.path.exists(file), f"Sound file {file} does not exist."try:
ifsys.platform!="win32":
if"linux"insys.platform:
check_call(["xdg-open", file])
elifsys.platform=="darwin":
check_call(["afplay", file])
else:
assertFalse, f"Unsupported platform: {sys.platform}."returnos.environ["PYGAME_HIDE_SUPPORT_PROMPT"] ="1"frompygameimportmixer# type: ignore # pylint: disable=allmixer.init()
mixer.music.load(file)
mixer.music.play()
whilemixer.music.get_busy():
time.sleep(0.01)
exceptExceptionasexc:
ifignore_errors:
warnings.warn(f"Cannot play {file} because of {exc}.")
else:
raise
I recommend that playsound moves to this code.
The text was updated successfully, but these errors were encountered:
This doesn't check for multiple audio players. Shout out to PreferredSoundPlayer for doing this. I can't find any check in playsound either, so i guess that PreferredSoundPlayer is the best option. Always DYOR though!
After trying to work around win32, macos and linux bugs I've gone ahead and removed playsound from my python project and replaced it with this cross platform solution.
I recommend that playsound moves to this code.
The text was updated successfully, but these errors were encountered: