Created
June 27, 2025 06:12
-
-
Save EncodeTheCode/4726abfb4d11b274b7874dc3aced3446 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, time | |
from pygame._sdl2 import mixer as m | |
class AE: | |
Q={'low':(11025,-8,1,512),'medium':(22050,-16,1,1024),'high':(44100,-16,2,2048),'ultra':(48000,-16,2,4096)} | |
def __init__(self,q='high'): | |
f=self.Q[q];m.init(f[0],f[1],f[2],f[3]) | |
def f(self,b,exts): | |
for e in exts: | |
n=f"{b}.{e}" | |
if os.path.exists(n): return n | |
raise FileNotFoundError(f"{b} not found") | |
def m(self,b,l=False,v=1): | |
s=m.Sound(self.f(b,['mp3']));s.set_volume(v) | |
return s.play(-1 if l else 0) | |
def w(self,b,l=False,v=1): | |
s=m.Sound(self.f(b,['wav']));s.set_volume(v) | |
return s.play(-1 if l else 0) | |
def s(self,c): | |
c and isinstance(c,m.Channel) and c.stop() | |
def a(self): m.stop() | |
def q(self): m.quit() | |
# Example | |
if __name__=='__main__': | |
ae=AE() | |
a,b,c,d=ae.m('background_music',True,.6),ae.m('ambience',True,.4),ae.w('click'),ae.w('explosion') | |
time.sleep(3);ae.s(c) | |
time.sleep(5);ae.s(b) | |
time.sleep(5);ae.q() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment