0

i use pygame.mixer.sound for audio and sender pyqt5 for event, but when i click on button play my audio file starts from the begining and plays together with previos audio file

def open(self):
    pygame.init()
    self.btn_play.clicked.connect(self.play)

def play(self):
    sender=self.sender()
    if sender==self.btn_play:
        self._music=pygame.mixer.Sound('music_file.wav')
        self._music.play()
    elif sender==self.btn_stop:
        self._music.stop()
eyllanesc
  • 190,383
  • 15
  • 87
  • 142
  • you should keep information (in some variable) that you already clicked button and don't start music again. – furas May 01 '19 at 21:55
  • 2
    you could try [pygame.mixer.get_busy](https://www.pygame.org/docs/ref/mixer.html#pygame.mixer.get_busy) to check if mixer is playing any sound - and skip new sound or stop previous one. Or try [pygame.mixer.Channel](https://www.pygame.org/docs/ref/mixer.html#pygame.mixer.Channel) which also has `get_busy` – furas May 01 '19 at 21:57

0 Answers0