Skip to main content
Clarified. Changed title to focus on error message, as that seems to be the main problem.
Source Link
Anko
  • 13.5k
  • 10
  • 56
  • 82

Why What does my script for playing musica "video system not initialised" error in pygame not workmean?

I'm trying to play music when a key is pressed in pygame, then print a message. I'm using Stani's Python Editor. When

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.

"pressedkeys = pygame.key.get_pressed() pygame.error: video system not initialised Script terminated."What am I doing wrong?

Any ideas? Thanks in advanceI'm using Stani's Python Editor.

Why does my script for playing music in pygame not work?

I'm trying to play music when a key is pressed in pygame, then print a message. I'm using Stani's Python Editor. 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."

Any ideas? Thanks in advance.

What does a "video system not initialised" error in pygame mean?

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.

Source Link

Why does my script for playing music in pygame not work?

I'm trying to play music when a key is pressed in pygame, then print a message. I'm using Stani's Python Editor. 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."

Any ideas? Thanks in advance.