我创建了一个按钮,该按钮可以打开下一个音频,但接下来的问题是:我使用了模块随机选择功能,其中一首歌曲的播放次数超过3次。如何进行不同的处理。 在循环版本中,将处理最后一首歌曲,是否可以在循环中设置一定的延迟,以便下次迭代会随着时间发生
def play(self):
self.indexsing=len(self.playlist)
self.send=self.sender()
self._music = pygame.mixer.Channel(0)
if self.send==self.btn_play:
self.playing = self._music.play(pygame.mixer.Sound('music/{0}'.format(self.playlist[1])))
self.btn_start_busy=pygame.mixer.get_busy()
elif self.send==self.btn_stop:
self._music.pause()
elif self.send==self.btn_unpause:
self._music.unpause()
elif self.send==self.next:
self.first_music=self.playlixst[2]
self.next_music=sample(self.playlist,len(self.playlist))
self._playing=self._music.play(pygame.mixer.Sound('music/{0}'.format(self.next_music)))
#loop
for song in range(len(self.playlist)):
self.next_music=self.playlist.pop(song)
self._playing = self._music.play(pygame.mixer.Sound('music/{0}'.format(self.next_music)))