#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    8
    Rep Power
    0

    Python3.2/Pygame problem.


    Hello.

    I am having a problem playing music in pygame, the file is a wav and I've never had this problem - so here is all the code.

    Code:
    import pygame, sys, time
    
    pygame.init()
    pygame.display.set_caption("Star Citizen - A Roguelike game")
    
    SWidth = 1280
    SHeight = 1024
    Screen = pygame.display.set_mode((SWidth, SHeight), 0, 32)
    
    pygame.mouse.set_visible(False)
        
    def Main():
        mmi = ("C:\\Python_Game\\Graphics\\SC_Logo.png")
        BGI = pygame.image.load(mmi).convert()
        Screen.blit(BGI, (0,0))
        pygame.display.update()
        pygame.mixer.music.load("C:\\Python_Game\\Sounds\\MT.wav")
        time.sleep(1)
        pygame.mixer.music.play()
        
        
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
    
    Main()
    Everything else works, but the console returns the error

    Code:
    Traceback (most recent call last):
      File "C:\Python_Game\MainGame.py", line 28, in <module>
        Main()
      File "C:\Python_Game\MainGame.py", line 17, in Main
        pygame.mixer.music.load("C:\\Python_Game\\Sounds\\MT.wav")
    pygame.error: Unable to load WAV file
    I use Sony Vegas 12 to render my sounds, and was wandering if pygame only supports a specific sound 'quality', if you will. Could this be the problem?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    On my system, if the file isn't found I get a different error.

    pygame.error: Couldn't open 'blah blah blah'
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    8
    Rep Power
    0
    Originally Posted by b49P23TIvg
    On my system, if the file isn't found I get a different error.

    pygame.error: Couldn't open 'blah blah blah'
    My computer knows where the file is, as it turns out the error you stated if I deliberately make the wrong file path. The problem with mine is it wont load it and I don't know why
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    194
    Rep Power
    2
    Try throwing this after the imports and see if it helps:
    Code:
    pygame.mixer.init()
    although that should get initialized when you call pygame.init() anyway.

    Not sure if this is the problem though. It sounds more like pygame doesn't like your particular wav file. Next step would be to try opening the file and resaving it with another application.

    You also might want to look into pygame.mixer.pre_init() although again I don't think this is actually the problem here.

    -Mek
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Kudos on you sir for making a roguelike game, I've been playing nethack for the last ten years and it's still one of my favourite games of all time.

    As Mekire is saying, try experimenting with pygame.mixer.init(), you might have to put in a few arguments depending on the frequency of the sample and such.

    http://www.pygame.org/docs/ref/mixer.html#pygame.mixer.init
    http://www.catb.org/esr/faqs/smart-questions.html#code
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    8
    Rep Power
    0

    Thank you.


    I finally resolved the problem in the end after ALOT of experimentation, and the problem was indeed with the wav file like I and you guys suspected. The sound quality is now lower (But I like it more this way), however, for those who may be interested and are suffering a similar problem the render specifications that work are as follows (Or so I believe with the default pygame mixer options):

    Audio: 48,000 Hz, 16 Bit, Stereo, PCM

    Broken down:
    Format = PCM (Uncompressed)
    Bit Depth = 16 Bit
    Channels = Stereo
    Sample Rate = 48,000 Hz

    Hope that helps some people.

IMN logo majestic logo threadwatch logo seochat tools logo