Hi.
I need to create a logo for the game.
It is necessary, that the sound was reproduced, and the program didn't work further until the end of playback. Also, so that if the user pressed Return, you could skip this. I decided to do this through a while loop. But it doesn't work correctly...
My sound class
from attr import attrs, attrib, Factory
import pygame
import time
pygame.mixer.init(frequency=44100, buffer=512)
@attrs
class sound():
handle=attrib(default=Factory(int))
def load(self,filename=""):
self.handle = pygame.mixer.Sound(filename)
def play(self):
self.handle.play()
def stop(self):
self.handle.stop()
def get_volume(self):
return self.handle.get_volume()
def set_volume(self, new_volume):
self.handle.set_volume(new_volume)
def fade(self, fadeSpeed):
self.handle.fadeout(fadeSpeed)
def isPlaying(self):
return self.handle.get_busy()
My logo function
import pygame
from AGK.audio import sound
from AGK.mainframe import keyboard
import time
dlgAudio = sound.sound()
def dlgPlay(dlgSound, dlgFade=False, fadeSpeed=1000):
dlgAudio.load(dlgSound)
dlgAudio.play()
while dlgAudio.isPlaying:
if keyboard.pressed() == pygame.K_RETURN:
if dlgFade == True:
dlgAudio.fade(fadeSpeed)
time.sleep(2)
break
If I press Return while the logo is playing, it works. Sound fadeing and exit from the loop. But if the sound plays to the end, then after the playback is completed, the loop continues to work until you press Return. Although the loop should work until the sound is played.
Why so? Who can helps me?