-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_manager.py
More file actions
29 lines (23 loc) · 818 Bytes
/
audio_manager.py
File metadata and controls
29 lines (23 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# audio_manager.py
# version 1.22.10
import pygame
from collections import defaultdict
class AudioManager:
def __init__(self):
pygame.mixer.init()
self.audio_files = defaultdict(lambda: None)
self.muted = False
def __del__(self):
pygame.mixer.quit()
def load_audio(self, file_path):
try:
audio = pygame.mixer.Sound(file_path)
self.audio_files[file_path] = audio
print(f"Loaded audio file: {file_path}")
except pygame.error as e:
print(f"Error loading audio file: {e}")
def play_audio(self, file_path):
if not self.muted and file_path in self.audio_files:
self.audio_files[file_path].play()
def toggle_mute(self):
self.muted = not self.muted