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 22, 2024
1 parent df9a5bf commit 9102b88
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 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,19 @@ 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(10):
if pygame.mixer and pygame.mixer.get_init():
return True
time.sleep(0.1)
pygame.mixer.init()
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 9102b88

Please sign in to comment.