Skip to content

Commit

Permalink
Try harder to initialize sound.
Browse files Browse the repository at this point in the history
  • Loading branch information
porridge committed Apr 23, 2024
1 parent df9a5bf commit 47437a7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion bambam.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from pygame.locals import Color, QUIT, KEYDOWN, MOUSEMOTION, MOUSEBUTTONDOWN, MOUSEBUTTONUP
import random
import sys
import time
from textwrap import fill

try:
Expand Down Expand Up @@ -452,11 +453,22 @@ def _add_base_dir(self, base_dir):
print(_('Using extension directory %s') % extensions_subdir)
self.extensions_dirs.append(extensions_subdir)

def _try_init_sound(self):
for _ in range(30):
if pygame.mixer and pygame.mixer.get_init():
return True
time.sleep(0.1)
try:
pygame.mixer.init()
except pygame.error:
pass
return pygame.mixer and pygame.mixer.get_init()

def _load_resources(self, args):
if not pygame.font:
print(_('Error: pygame fonts not available. Exiting.'), file=sys.stderr)
sys.exit(1)
if not pygame.mixer or not pygame.mixer.get_init():
if not self._try_init_sound():
print(_('Warning: Sound support not available.'), file=sys.stderr)
self._sound_enabled = False
else:
Expand Down

0 comments on commit 47437a7

Please sign in to comment.