playing music in python using pygame module

 playing music in python using pygame module


from pygame import mixer as mx
mx.init() #start mixer
mx.music.load("no_copyright_dubstep.mp3") #load mp3 file
mx.music.set_volume(0.7) #set volume
mx.music.play() #play music
while(1):
print("inpput 'p' to pause, 'r' to resume, 'e' to exit")
inp=input()
if inp=="p":
mx.music.pause() #pause the music
elif inp == "r":
mx.music.unpause() #resume the music
elif inp == "e":
mx.music.stop() # stop the music
break
else:
print("wrong input")

Comments