def music_player(): #function defination mi.init() mu.set_volume(0.7) mu.load(random.choice(songs)) print( "*******************************************************************") print("\t\tWELCOME TO MY MUSIC_PLAYER") print( "*******************************************************************") print("press 'a' to PLAY | press 'r' to RESUME | press 'n' for next song") print("press 's' to STOP | press 'p' to PAUSE") print( "--------------------------------------------------------------------\n" ) while True: query = input("") if query == 'a': mu.play() print("Player Start!") elif query == 'r': mu.unpause() print("Song resume") elif query == 'p': print("song pause!") mu.pause() elif query == 'n': print("Listen next song!") mu.stop() time.sleep(1) mu.load(random.choice(songs)) mu.play() elif query == 's': mu.stop() break print("Player get quit !")
def volume_value(self): global volume volume = self.slider.value() volume = float(volume / 100) self.config["settings"]["volume"] = str(volume) with open("settings.ini", "w") as file: self.config.write(file) mixer_music.set_volume(volume)
def soundon(i): # global value # value=value+i # if value <= 1.0: # sound=value/100 try: mixer_music.set_volume(5.0) except Exception as e: pass
def adaptMusic(self, emotion): if emotion in {'happy', 'neutral', 'angry'}: if self.emotion != emotion: self.emotion = emotion if mixer_music.get_busy(): mixer_music.fadeout(500) else: if mixer_music.get_volume() <= .95: mixer_music.set_volume(mixer_music.get_volume() + 0.010) if not mixer_music.get_busy(): mixer_music.set_volume(0) if emotion == 'happy': mixer_music.load("lib/happy.mp3") elif emotion == 'angry': mixer_music.load("lib/angry.mp3") else: mixer_music.load("lib/neutral.mp3") mixer_music.play()
def run(self): mixer.init(44100, -16, 2, 2048) rand = random.choice(self.path_and_file) map_title = str(rand[0]).split("\\")[-1] mixer_music.load(f"{rand[0]}\{rand[1]}") mixer_music.play() mixer_music.set_endevent(self.NEXT) mixer_music.set_volume(self.volume) self.signals.signal_str.emit(map_title) running = True while running: for event in pygame.event.get(): if event.type == self.NEXT: rand = random.choice(self.path_and_file) map_title = str(rand[0]).split("\\")[-1] self.signals.signal_str.emit(map_title) mixer_music.load(f"{rand[0]}\{rand[1]}") mixer_music.play()
def soundoff(): try: mixer_music.set_volume(0.0) except Exception as e: pass
"352588__humanoidefilms__umbrella-opening-slow.wav") #Creation du son sonChenille.set_volume(0.5) blibliBruit["sonChenille"] = sonChenille #Ajout du son a la blibliotheque chute = mixer.Sound( chemson + "159408__noirenex__life-lost-game-over.wav") #Creation du son chute.set_volume(0.8) blibliBruit["chute"] = chute #Ajout du son a la blibliotheque blibliSon = {} #Blibliotheque generale blibliSon["Bruit"] = blibliBruit #Ajout de la blibliotheque secondaire music.load(chemson + "397089__timbre__remix-of-erokia-s-freesound-394011.wav") music.set_volume(0.5) fen = Tk() #Creation fenetre fen.resizable(False, False) #Empeche redefinition fenetre fen.title("Objectif Terre") #Creation des in terfaces interface1 = ModuleInterface.InterfaceAcceuil(fen, blibliSon) interface2 = ModuleInterface.InterfaceNiveau1(fen, blibliSon) interface3 = ModuleInterface.InterfaceNiveau2(fen, blibliSon) interface4 = ModuleInterface.InterfaceNiveau3(fen, blibliSon) interface5 = ModuleInterface.InterfaceNiveau4(fen, blibliSon) interface6 = ModuleInterface.InterfaceSauvegarde(fen, blibliSon) interface7 = ModuleInterface.InterfaceManuelDutilisation(fen, blibliSon) interface8 = ModuleInterface.InterfaceMappeur(fen, blibliSon)
def __init__(self): global volume super(Main, self).__init__() mixer.init(44100, -16, 2, 2048) pygame.init() self.signals = get_signal() self.signals.signal_str.connect(self.change_map_title) ssf = open("style.stylesheet", "r").read() self.config = configparser.ConfigParser() self.config.read("settings.ini") self.path = self.config["settings"]["path"] self.volume = float(self.config["settings"]["volume"]) volume = self.volume mixer_music.set_volume(self.volume) self.setWindowTitle("Osu Player") self.setStyleSheet(ssf) self.setMinimumWidth(500) playrandom = QPushButton("Play Random") pause = QPushButton("Pause") unpause = QPushButton("Unpause") restart = QPushButton("Restart") self.map_name = QLabel() self.map_name.setStyleSheet(ssf) self.slider = QSlider() self.slider.setOrientation(Qt.Horizontal) self.slider.TickPosition(QSlider.NoTicks) self.slider.setMinimum(0) self.slider.setMaximum(100) self.slider.setStyleSheet(ssf) self.slider.setValue(self.volume * 100) template = QFormLayout() template.addRow(self.map_name) template.addRow(playrandom) template.addRow(pause, unpause) template.addRow(restart) template.addRow(self.slider) self.templatewidget = QWidget() self.templatewidget.setLayout(template) self.setCentralWidget(self.templatewidget) self.all_files = [] self.path_and_file = [] for root, dirs, files in os.walk(self.path): self.all_files.append((root, files)) for dirs_files in self.all_files: for file in dirs_files[1]: if file.endswith(".mp3"): self.path_and_file.append((dirs_files[0], file)) self.threadpool = QThreadPool() self.threadpool.setMaxThreadCount(1) print( f"Multithreading with maximum {self.threadpool.maxThreadCount()} threads" ) playrandom.pressed.connect(self.play) pause.pressed.connect(self.pause) unpause.pressed.connect(self.unpause) restart.pressed.connect(self.restart) self.slider.valueChanged.connect(self.volume_value)