Wolfmann Games
Wolfmann Games

Reputation: 150

How to continue a sound in Pygame?

I have a sound that I wish to play.

My code;

[...]
        if var_camera_flip == 1:
            if var_camera != 4:
                pygame.mixer.Channel(2).play(pygame.mixer.Sound(r'audio\camera\camera motor.mp3'), -1)
            else:
                pygame.mixer.Channel(2).stop()
        else:
            pygame.mixer.Channel(2).stop()
[...]

This code is in a subroutine that I call. What happens is that it restarts the sound each time it runs. What I want is that is the sound to continue playing until it is told not to.

Upvotes: 1

Views: 528

Answers (1)

Rabbid76
Rabbid76

Reputation: 211258

Do not stop a sound, but pause it with pygame.mixer.Channel.pause:

pygame.mixer.Channel(2).pause()

Once a sound is paused it can be continued with pygame.mixer.unpause:

pygame.mixer.Channel(2).unpause()

Upvotes: 2

Related Questions