I'm trying to play music when a key is pressed in pygame, then print a message.
When I run this script:
import pygame
import time
pressedkeys = pygame.key.get_pressed()
pygame.init() #initialize pygame
pygame.mixer.pre_init(44100, -16, 2, 2048) # setup mixer to avoid sound lag
try:
firstMusic = pygame.mixer.Sound("C:\(pathForMyMusicFile).wav") #load sound
secondMusic = pygame.mixer.Sound("C:\(pathForMy2ndMusicFile).wav") #load sound
except:
raise UserWarning, "could not load or play soundfiles"
if pressedkeys[pygame.K_SPACE]:
firstMusic.play(-1)
time.sleep(2)
I get this error:
pressedkeys = pygame.key.get_pressed() pygame.error: video system not initialised Script terminated.
What am I doing wrong?
I'm using Stani's Python Editor.
pre_init
beforeinit
. – congusbongus May 5 '14 at 5:54