Last active
March 5, 2018 05:52
-
-
Save nagayev/3fe2b8cb752f1c243937fbccd2739a41 to your computer and use it in GitHub Desktop.
This file contains 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
class Music: | |
def __init__(self): | |
try: | |
pygame.init() | |
self.mixer=pygame.mixer | |
except: | |
try: | |
from pygame import mixer,init | |
init() | |
self.mixer=mixer | |
except: | |
print('pleaze install pygame') | |
raise SystemExit | |
def load(self,filename): | |
#load phone music | |
self.filename=filename | |
self.mixer.music.load(self.filename) | |
def play(self): | |
self.mixer.music.play() | |
def stop(self): | |
self.mixer.music.stop() | |
def pause(self): | |
music.pause() | |
class Sound(Music): | |
def __init__(self): | |
super().__init__() | |
def play(self,time=2): | |
self.mixer.music.play() | |
sleep(time) | |
self.mixer.music.stop() |
This file contains 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
#Test usage of this lib | |
from time sleep | |
a=Music() | |
a.load('theme.mid') | |
a.play() #playing phone music | |
a=Sound() | |
a.load('music.mid') | |
a.play(2) #playing music for two seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment