Pygame - Sound delay

前端 未结 7 1249
广开言路
广开言路 2020-12-16 01:32

I\'ve made a button class that checks if a button is selected (when the mouse is hovering over the button). When the button is selected, unselected or clicked it plays a wav

7条回答
  •  旧时难觅i
    2020-12-16 02:21

    Simply decreasing the size of the buffer, as often suggested for this problem, did not work for me. I found this solution. When initiating the mixer twice, the delay completely disappeared:

    import pygame
    
    pygame.mixer.pre_init(22050, -16, 2, 1024)
    pygame.init()
    pygame.mixer.quit()
    pygame.mixer.init(22050, -16, 2, 1024)
    

    It's a bit dirty and I don't know why it works, but hopefully it solves the problem for some people.

    Tested on Ubuntu 16.04 LTS with Python 3.6 and pygame 1.9.4

提交回复
热议问题