[Pygame] Unable to open sound file

[Pygame] Unable to open sound file

Postby metulburr » Mon Jun 03, 2013 1:16 am

Googling comes up with what appears to be this error when you dont init pygame or the mixer, however, i have done so with either or, and both, jsut to see if somethign would work.

main.py
Code: Select all
import pygame

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

sound = pygame.mixer.Sound('censor1.wav')
#sound2 = pygame.mixer.Sound('censor2.wav')

sound.play()
#sound2.play()


listing directory, execution, and traceback:
Code: Select all
metulburr@ubuntu:~/programs/$ ls
censor1.wav  censor2.wav  main.py
metulburr@ubuntu:~/programs/$ python3 main.py
Traceback (most recent call last):
  File "main.py", line 8, in <module>
    sound = pygame.mixer.Sound('censor1.wav')
pygame.error: Unable to open file 'censor1.wav'


So the mixer initilaized, pointing to the correct path, and not sure why its not able to open the wav file. I checked it with another wav file and that one worked while this one does not.

EDIT:
however using a completely different wav file from a different site, plays no problem:
Code: Select all
import pygame
import os
import time

#pygame.init()
pygame.mixer.init()

sound = pygame.mixer.Sound('test.wav')
#sound2 = pygame.mixer.Sound('censor2.wav')

sound.play()
time.sleep(3)
#sound2.play()



Code: Select all
metulburr@ubuntu:~/programs/$ ls
censor1.wav  censor2.wav  main.py  test.wav
metulburr@ubuntu:~/programs/$ python3 main.py
metulburr@ubuntu:~/programs/
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1374
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: [Pygame] Unable to open sound file

Postby metulburr » Mon Jun 03, 2013 2:38 am

this would be an example. You would expect from the initial print of listdir(), that it will play both sounds, but in fact only the test.wav is played, and i can never get censor1.wav or censor2.wav to play with pygame.

Code: Select all
import pygame
import os
import time

pygame.mixer.init()
print(os.listdir())
try:
   sound = pygame.mixer.Sound('censor1.wav')
   print('censor1.wav')
   sound.play()
   time.sleep(3)
except pygame.error:
   pass
   

sound = pygame.mixer.Sound('test.wav')
print('test.wav')
sound.play()
time.sleep(3)


output:
['censor2.wav', 'test.wav', 'main.py', 'censor1.wav']
test.wav

New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1374
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest