2

i have been trying to use pyGame to play sounds whilst at the same time looping music in the background -

i've tested it using Horts Jens' demo code

import pygame
import os

pygame.mixer.pre_init(44100, -16, 2, 2048) # setup mixer to avoid sound lag
pygame.init()                              #initialize pygame

# look for sound & music files in subfolder 'data'
pygame.mixer.music.load(os.path.join('data', 'foxhaunt.ogg'))#load music
jump = pygame.mixer.Sound(os.path.join('data','scream.wav'))  #load sound
fail = pygame.mixer.Sound(os.path.join('data','fail.wav'))  #load sound

# play music non-stop
pygame.mixer.music.play(-1)
if "a" in answer:
        jump.play()
        print "playing jump.wav once"
    elif "b" in answer:
        fail.play()
        print "playing fail.wav once"
    elif "m" in answer:
        if pygame.mixer.music.get_busy():
            pygame.mixer.music.stop()
        else:
            pygame.mixer.music.play()
    elif "q" in answer:
        #break from gameloop
        gameloop = False
    else:
        print "please press either a, b, m or q and ENTER"

What happens is that the call to pygame.mixer.music.play(-1) works fine and I hear the music, however the calls to jump.play() and fail.play() don't do anything. I even tried putting in a delay after the call to sound>.play() to ensure that there was enough time for the sound play to complete - but still nothing.

Do you have ideas on what I should looks for?

the platform is a Raspberry Pi running Wheezy

pygame: 1.9.1release+dfsg-8 - python2.7-pygame python2.6-pygame

can you suggest how I might get this working or what I should check in order to find out why it's not working?

Cheers

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
scuffster
  • 51
  • 1

0 Answers0