Python 7 Levels, L6, Unit 67, pygame Sounds

Powered By EmbedPress

Exercise 1:

import pygame
pygame.init()
pygame.mixer.init()

screen = pygame.display.set_mode([640,480])
pygame.time.delay(1000)

s1 = pygame.mixer.Sound("splat.wav")
s1.play()

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
pygame.quit()

Exercise 2:

import pygame
pygame.init()
pygame.mixer.init()

screen = pygame.display.set_mode([640,480])
pygame.time.delay(1000)

pygame.mixer.music.load("bg_music.mp3") 
pygame.mixer.music.play(1)

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
pygame.quit()

Exercise 3:

import pygame
pygame.init()
pygame.mixer.init()

screen = pygame.display.set_mode([640,480])
pygame.time.delay(1000)

s1 = pygame.mixer.Sound("splat.wav")
s1.set_volume(0.20)
s1.play()

pygame.mixer.music.load("bg_music.mp3")
pygame.mixer.music.set_volume(0.10) 
pygame.mixer.music.play()

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
pygame.quit()

Exercise 4:

import pygame
pygame.init()
pygame.mixer.init()

screen = pygame.display.set_mode([640,480])
pygame.display.set_caption("Sound Test")
s1 = pygame.mixer.Sound("splat.wav")
s1.set_volume(0.02)

pygame.mixer.music.load("bg_music.mp3")
pygame.mixer.music.set_volume(0.01)
pygame.mixer.music.play()

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    if not pygame.mixer.music.get_busy():
        '''get_busy() to check music is played over or not'''
        s1.play()
        pygame.time.delay(1000)
        running = False
        
pygame.quit()

dahan1999

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts