简体   繁体   中英

how can I play a sound with pygame while the system is waiting?

I'm using the pygame function pygame.time.delay() to make pygame freeze while presenting some pictures or text, and I want to play a sound at the same time.

The problem, I think, is that in order for pygame mixer to work the main loop must be running, so putting the system on wait it also stops the mixer.

Any easy way to solve this problem? thanks

pygame.time.delay() is a bad idea for waiting while presenting things, it not only will prevent you from playing music it can also freeze your screen (blank screen).

You should process events and update the display although you have static image.

Some alternatives are:

  1. Use a counter in your loop to know how long you should keep the same image in the screen.
  2. Use a timer to receive a User Event that will notify you that you need to change the current state.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM