Guest User

Untitled

a guest
Jan 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. import sys, pygame
  2. from PyQt5.QtWidgets import *
  3. from PyQt5.QtCore import *
  4.  
  5. class AudioPlayer(QObject):
  6. def __init__(self, filename):
  7. super().__init__()
  8. self.filename = filename
  9. print("Created " + filename)
  10.  
  11. def play(self):
  12. print("Playing " + self.filename)
  13. pygame.mixer.music.load(self.filename)
  14. pygame.mixer.music.play()
  15.  
  16. class Session(QMainWindow):
  17. def __init__(self):
  18. super().__init__()
  19. self.mainWid = QWidget(self)
  20. self.vbox = QVBoxLayout()
  21. self.mainWid.setLayout(self.vbox)
  22. self.setCentralWidget(self.mainWid)
  23. self.show()
  24.  
  25. pygame.mixer.init()
  26.  
  27. filenames = [r'C:...file1.mp3', r'C:...file2.mp3']
  28.  
  29. for filename in filenames:
  30. playButton = QPushButton('Play', self)
  31. localPlay = AudioPlayer(filename)
  32. playButton.clicked.connect(localPlay.play)
  33. self.vbox.addWidget(playButton)
  34.  
  35. if __name__ == '__main__':
  36. app = QApplication(sys.argv)
  37. Session()
  38. sys.exit(app.exec_())
  39.  
  40. admin@home> python main2.py
  41. Created C:...file1.mp3
  42. Created C:...file2.mp3
  43. admin@home>
  44.  
  45. class Session(QMainWindow):
  46. def __init__(self):
  47.  
  48. # ...
  49.  
  50. filenames = [r'C:...file1.mp3', r'C:...file2.mp3']
  51.  
  52. pygame.mixer.music.load(filenames[0])
  53. pygame.mixer.music.play()
Add Comment
Please, Sign In to add comment