My code, Vincible.py, is located in
C:\Users\Nick\Desktop\Vincible
and I'm trying to access the midi files located in
C:\Users\Nick\Desktop\Vincible\Audio
I've put together:
#!C:\Python33\python.exe
import sys, pygame, os.path
print("Loading...")
pygame.mixer.pre_init(44100, -16, 2, 2048)
try:
pygame.mixer.music.load(os.path.join('Audio', 'title.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'dun1.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'dun2.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'dun3.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'dun4.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'dun5.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'dun6.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'echostheme'))
pygame.mixer.music.load(os.path.join('Audio', 'town1.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'town2.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'town3.midi'))
except:
raise UserWarning("Could not load or play soundfiles in 'Audio' folder")
pygame.init()
size = width, height = 580, 444
screen = pygame.display.set_mode(size)
print("Loaded!")
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
pygame.mixer.Sound('title.midi').play()
Upon running it, it runs the except bit and I'm struggling to figure
out how to successfully do this. I don't typically work with
accessing files from different paths in Python, so your help is very
much appreciated.
Edit: As subtly requested, I removed the try/except from my code.
Here is the new code:
#!C:\Python33\python.exe
import sys, pygame, os.path
print("Loading...")
pygame.mixer.pre_init(44100, -16, 2, 2048)
pygame.init()
pygame.mixer.music.load(os.path.join('Audio', 'title.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'dun1.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'dun2.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'dun3.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'dun4.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'dun5.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'dun6.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'echostheme'))
pygame.mixer.music.load(os.path.join('Audio', 'town1.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'town2.midi'))
pygame.mixer.music.load(os.path.join('Audio', 'town3.midi'))
size = width, height = 580, 444
screen = pygame.display.set_mode(size)
print("Loaded!")
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
pygame.mixer.Sound('title.midi').play()
this time putting out:
Traceback (most recent call last):
File "C:\Users\Nick\Desktop\Vincible\Vincible.py", line 8, in <module>
pygame.mixer.music.load(os.path.join('Audio', 'title.midi'))
pygame.error: Couldn't open 'Audio\title.midi'
The file isn't corrupt and it is indeed in
Vincible\Audio
but it's still returning this error. I'd imagine it has something to
do with my use of
os.path.join
but then again, I'm new to the os.path module. Any help is very much
appreciated.
Note: I took away all of the other .midi files to make the code smaller/more readable, after the issue has been resolved they'll be added in the correct manner.
When ran, the interpreter raises another pygame.error "The file couldn't be opened" on line 13 (where I load "title.midi"). Any help is appreciated.