So i have this piece of code which will play a sound but it only works if it is in the same directory
# Doesnt work
current_directory = os.getcwd()
path = os.path.join(current_directory + "\sounds\\monster_roar.wav")
music = pyglet.resource.media(path)
# does work
music = ("monster_roar.wav")
#music.play()
pyglet.resource.ResourceNotFoundException: Resource "C:\\Users\\Joshua Nixon\\Documents\\college_work\\extended_project\\game\\new\\sounds\\monster_roar.wav" was not found on the path. Ensure that the filename has the correct captialisation.
What am i missing?
You should consider using an absolute path instead of a relative path in cases like this. However, your error can likely be fixed with the following:
Instead of using music = pyglet.resource.media(path)
... try using music = pyglet.media.load(path)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.