Answer the question
In order to leave comments, you need to log in
Why does Python code fail?
I have a code that displays in a list the MP3 files that are in the selected folder. I wanted to add the ability to play the file, the path to which was registered in the code itself. If you click on the button, the file will play, but the VS Code terminal will start spamming the same message: "QCoreApplication::exec: The event loop is already running". If you wait a little longer, a message will appear that the application is not responding, the screen will be lower. I tried to run separately the code responsible for playing the file, no errors occurred. Please tell me where I might have made a mistake
import sys, os, pygame, mutagen.mp3, design
from PyQt5 import QtWidgets
class Browse(QtWidgets.QMainWindow, design.Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.ButtonBrowse.clicked.connect(self.browse_folder)
self.ButtonPlay.clicked.connect(self.play_track)
def browse_folder(self):
self.listWidget.clear()
directory = QtWidgets.QFileDialog.getExistingDirectory(self, "Выберите папку")
if directory:
for file_name in os.listdir(directory):
if file_name.endswith(".mp3") | file_name.endswith(".wav"):
self.listWidget.addItem(file_name)
def play_track(self):
song_file = "C:\\Users\\101ap\\Desktop\\Player\\music\\LINKIN PARK\\Meteora\\13. Numb.mp3"
mp3 = mutagen.mp3.MP3(song_file)
pygame.mixer.init(frequency=mp3.info.sample_rate)
pygame.mixer.music.load(song_file)
pygame.mixer.music.play()
input()
def main():
app = QtWidgets.QApplication(sys.argv)
window = Browse()
window.show()
app.exec_()
if __name__ == '__main__':
main()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question